如何设置基于计时器的通知?

HRJ*_*HRJ 9 notification dbus

作为一个强迫性的计算机用户,我整天都在它面前。当我在做我的伴奏时,我有时会忘记时间。我需要一个通知服务来提醒我当前时间,通过弹出通知或正在播放的声音或两者兼而有之。

对于弹出窗口,我找到了使用DBus API的免费桌面通知标准。

我能够使用图形 DBUS 浏览器DFeet创建通知。我使用了以下参数:

"wakeup", 1234, "", "The time is", "9PM", [], [], 1
Run Code Online (Sandbox Code Playgroud)

到目前为止它工作正常,但我怎么能从这里走得更远呢?

  • 如何从命令行调用它?
  • 如何自动执行此命令?是cron仍然自动基于时间行动的建议呢?
  • 如何在弹出窗口中播放声音?是通过 FreeDesktop API 还是通过媒体播放器?

一个完整的解决方案将不胜感激,也许对其他人也有用。

HRJ*_*HRJ 7

因为我不能使用,dbus-send所以我写了一个 python 脚本。pynotify 模块在内部使用dbusAPI。为了获得额外奖励,我在消息中添加了幸运饼干。奇迹般有效:

#!/usr/bin/env python
"""python 2.7 script that creates a notification using pynotify. It shows the current time and a small fortune cookie"""
try:
  import pynotify
  import time
  import subprocess
  if pynotify.init("Wakeup service"):
    subprocess.Popen(["paplay", "/usr/share/sounds/ubuntu/stereo/message.ogg"])

    # You can get more stock icons from here: http://stackoverflow.com/questions/3894763/what-icons-are-available-to-use-when-displaying-a-notification-with-libnotify
    timeStr = time.strftime("%I:%M %p %d %b")
    cookie = subprocess.check_output(["/usr/games/fortune", "-s"])
    n = pynotify.Notification(timeStr, cookie, "/usr/share/app-install/icons/ktimer.png")
    n.set_timeout(1)
    n.show()
  else:
    print "problem initializing the pynotify module"
except Exception as exc:
  print "Exception", exc
Run Code Online (Sandbox Code Playgroud)

然后我使用cron. 该crontab条目如下所示:

0,30 * * * * DISPLAY=:0 ./local/bin/notify_new.py
Run Code Online (Sandbox Code Playgroud)

更新:添加了使用脉冲音频播放声音的方法


Jo-*_*tad 3

您可以使用 dbus-send 命令发送消息。有关更多详细信息,请参阅man:dbus-send 。

  • 感谢您指向“dbus-send”的指针。不幸的是,它在这种情况下不起作用,因为“dbus-send”无法创建包含 API 所需的变体的字典 (3认同)