vav*_*ava 127 linux notifications ubuntu
大多数应用程序可以对出现在屏幕右上角的事件显示格式良好的通知。我即将编写一个 bash 脚本,它将在后台进行长时间的处理,我真的很想知道它什么时候完成。如何显示来自 bash 脚本的漂亮通知?
小智 148
如果您在 Jaunty 中使用新的通知系统,您需要notify-send命令
notify-send - a program to send desktop notifications
SYNOPSIS
With notify-send you can sends desktop notifications to the user via
a notification daemon from the command line. These notifications can be
used to inform the user about an event or display some form of information
without getting in the user's way.
OPTIONS
-u, --urgency=LEVEL
Specifies the urgency level (low, normal, critical).
-t, --expire-time=TIME
Specifies the timeout in milliseconds at which to expire the notification.
-i, --icon=ICON[,ICON...]
Specifies an icon filename or stock icon to display.
-c, --category=TYPE[,TYPE...]
Specifies the notification category.
Run Code Online (Sandbox Code Playgroud)
vav*_*ava 40
找到了另一种方式,通过Zenity
echo 'message:hi' | zenity --notification --listen
Run Code Online (Sandbox Code Playgroud)
或者像这样:
zenity --notification --text "System update necessary!"
Run Code Online (Sandbox Code Playgroud)
(这也有已经安装在 Ubuntu 上的好处。)
Gab*_*les 15
在 Ubuntu 14.04、16.04、18.04、20.04 上测试。来自 Ubuntu 20.04 的屏幕截图。
[运作良好] 4~10 秒后自动关闭的弹出通知(以某种方式与您的操作系统设置相关联?):
notify-send "Hello world"
Run Code Online (Sandbox Code Playgroud)
带有单击按钮的弹出窗口:
窗口没有自动对焦:
来源:我自己;注意:对于基于 Unity 的较旧版本的 Ubuntu,例如 16.04,-t
对于除 0--how 愚蠢之外的所有值都将被忽略。:(。对于较新的基于 Gnome 的 Ubuntu 版本,例如 18.04 或 20.04,-t
完全被忽略。因此,在较旧的基于 Unity 的 Ubuntu 版本(例如 16.04)上,使用-t 0
原因按钮显示,但在较新的基于 Gnome 的版本,它没有。这意味着对于下面显示的 Ubuntu 20.04 屏幕截图,行为和外观notify-send -t 0 "Hello world"
与notify-send "Hello world"
上面完全相同。
notify-send -t 0 "Hello world"
Run Code Online (Sandbox Code Playgroud)
在 Ubuntu 18.04 或 20.04 或更高版本上,只需添加-u critical
到命令中即可让它无限期地保持打开状态,直到您单击它的任意位置!:
notify-send -u critical "Hello world"
Run Code Online (Sandbox Code Playgroud)
或窗口确实获得自动对焦:
zenity --info --title "Hello" --text "World"
Run Code Online (Sandbox Code Playgroud)
注意:在您单击OK按钮之前,窗口不会关闭。
来源:https : //askubuntu.com/a/804475/327339
[我的最爱] 窗口在指定--timeout
的秒数后自动关闭,或者在您单击“确定”按钮后!
zenity --info --title "Hello" --text "World" --timeout=2
Run Code Online (Sandbox Code Playgroud)
【超级难看】
xmessage 'hello world'
Run Code Online (Sandbox Code Playgroud)
注意:在您单击okay按钮之前,窗口不会关闭。
来源:http : //www.linux-commands-examples.com/xmessage
kol*_*pto 13
对于 KDE 用户:
$ kdialog --title "Long process completed!" --passivepopup "This popup will disappear in 5 seconds" 5 &
Run Code Online (Sandbox Code Playgroud)