从 bash 脚本激活 KDE 4 通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1379804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:11:05  来源:igfitidea点击:

Activating KDE 4 notifications from bash scripts

bashscriptingkdekde4

提问by Massimiliano Fliri

I have a bash script activated by crontab and running in background. I would like to add to it the ability to send notifications during the execution. My KDE 4 desktop has a fancy notification system which pops out non-modal messages from the tray bar, and this would be perfect for my needs. So I was searching for a way to generate these notifications from a bash scripts, but I have almost no knowledge of the KDE platform and so I'm stuck. Can anybody point me to a solution?

我有一个由 crontab 激活并在后台运行的 bash 脚本。我想添加在执行过程中发送通知的能力。我的 KDE 4 桌面有一个花哨的通知系统,可以从托盘栏中弹出非模式消息,这非常适合我的需要。所以我正在寻找一种从 bash 脚本生成这些通知的方法,但我几乎不了解 KDE 平台,所以我被卡住了。有人可以指出我的解决方案吗?

回答by Alan Haggai Alavi

kdialog's passive popup option can be used.

kdialog可以使用被动弹出选项。

kdialog --passivepopup <text> <timeout>

Example:

例子:

kdialog --passivepopup 'This is a notification' 5

回答by mzuther

You may also use notify-send(on Debian-based systems, install the libnotify-binpackage):

您还可以使用notify-send(在基于 Debian 的系统上,安装libnotify-bin软件包):

notify-send -i 'dialog-information' 'Summary' '<b><font color=red>Message body.'

To my best knowledge, this should work on several window managers (such as KDE and Gnome).

据我所知,这应该适用于多个窗口管理器(例如 KDE 和 Gnome)。

回答by user3220705

kdialog --passivepopup 'message including html' timeout

is an option for KDE where the timeout is not necessary. you can tune this even with adding a headline (--title) and so on --> see kdialog --help

是 KDE 的一个选项,其中不需要超时。即使添加标题 ( --title) 等,您也可以对此进行调整--> 参见 kdialog --help

on the one hand it is worth mentioning, that kdialog was installed on my openSuSE KDE4 system whereas notify-send is not installed here.

一方面值得一提的是,kdialog 安装在我的 openSuSE KDE4 系统上,而这里没有安装 notify-send。

on the other hand the advantage of notify-send is that you can use it with different desktop environments

另一方面,通知发送的优点是您可以在不同的桌面环境中使用它

回答by user303371

Confirm that notify-send works with XFCE4 (Debian-based Mint), except the <b><font color=red>didn't work for me. For some reason it made the Message body text dark grey (virtually illegible), so I left that html out and the header ('Summary') and body text both come up white.

确认通知发送适用于 XFCE4(基于 Debian 的 Mint),除非它对<b><font color=red>我不起作用。出于某种原因,它使消息正文文本呈深灰色(几乎难以辨认),因此我将该 html 省略了,标题(“摘要”)和正文文本都显示为白色。

What is cool is that you can put an absolute path to the icon your prefer -- e.g. -i '~/myapps/foobarapp/icons/64x64/64x64.png'

很酷的是,您可以为您喜欢的图标添加绝对路径——例如 -i '~/myapps/foobarapp/icons/64x64/64x64.png'