技术技巧:使用 notify-send 从您的脚本获取通知
发布于 2009 年 9 月 2 日
Notify-send 是一个非常棒的应用程序,可以在事件发生时通知您。例如,脚本运行完成。
如果您的机器上尚未安装 notify-send,请从您的存储库安装 "libnotify1"(或可能只是 "libnotify")软件包。
安装完成后,您只需在命令行输入以下内容,即可在系统托盘附近显示弹出消息
notify-send "hello"
默认情况下,消息将显示 5 秒钟。要更改消息的显示时长,请使用 "-t" 开关。这将以毫秒为单位更改消息的显示时长。输入 "-t 0" 以使消息一直显示,直到用户关闭它。
notify-send "This message will be displayed for 3 seconds" -t 3000 notify-send "Click me to close me." -t 0
您甚至可以向通知添加标题和图标。
notify-send "This is the Title" \ "Check out the cool icon" \ -i /usr/share/pixmaps/gnome-terminal.png
如果在脚本中使用,您可以通过将命令放在循环中来设置它定期通知您
#!/bin/bash while [ 1 ]; do notify-send "Up Time" "`uptime`" sleep 5m done