时间到达下午 4:00 时弹出通知?

Kre*_*dns 25 linux bash notifications notify-osd ubuntu

我想知道是否有办法在特定时间从命令行显示通知或其他内容。就像时钟在下午 4:00 敲响一样。如果它使用 Ubuntu 的 notify-osd 工具显示它会很好:

在此处输入图片说明

jam*_*raa 41

正如许多其他评论者所说,每天执行此操作的最佳方法是使用 cron,但如果您只想执行一天或偶尔执行此操作,则可以使用以下at命令:

echo 'notify-send "Work day is done!"' | at 4:00PM 
Run Code Online (Sandbox Code Playgroud)

您可以通过at多种方式使用,包括作为茶计时器:

echo 'notify-send "Get your tea!"' | at now + 3 minutes 
echo 'notify-send "Meeting in 1 hour with the big boss!"' | at 1pm tomorrow 
Run Code Online (Sandbox Code Playgroud)

这对于那些一次性命令非常有用。

查看at 联机帮助页以了解更多语法优势。


小智 15

使用notify-send发送通知。将其设置为 cron 作业。

  • 但这不是开箱即用的。`notify-send` 需要一些 env 变量,默认情况下无法从 cron 获得这些变量? (3认同)

Joh*_*n T 11

您可以像这样向 notify-osd 发送命令:

notify-send "Go to bed!"
Run Code Online (Sandbox Code Playgroud)

下午 4 点的每日通知的 crontab 如下所示:

0 16 * * * /home/username/notify.sh
Run Code Online (Sandbox Code Playgroud)