作为一个强迫性的计算机用户,我整天都在它面前。当我在做我的伴奏时,我有时会忘记时间。我需要一个通知服务来提醒我当前时间,通过弹出通知或正在播放的声音或两者兼而有之。
对于弹出窗口,我找到了使用DBus API的免费桌面通知标准。
我能够使用图形 DBUS 浏览器DFeet创建通知。我使用了以下参数:
"wakeup", 1234, "", "The time is", "9PM", [], [], 1
Run Code Online (Sandbox Code Playgroud)
到目前为止它工作正常,但我怎么能从这里走得更远呢?
cron仍然自动基于时间行动的建议呢?一个完整的解决方案将不胜感激,也许对其他人也有用。
因为我不能使用,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)
更新:添加了使用脉冲音频播放声音的方法
您可以使用 dbus-send 命令发送消息。有关更多详细信息,请参阅man:dbus-send 。
| 归档时间: |
|
| 查看次数: |
1843 次 |
| 最近记录: |