有什么方法可以使用Python读取Linux桌面通知吗?

时间:2019-08-23 21:45:44

标签: python-3.x linux notifications dbus notify

我需要阅读使用Python的Linux桌面通知。我的头没用了,我想不出办法。

这是我使用dbus可以做的最好的事情:

import gi.repository.GLib
import dbus
from dbus.mainloop.glib import DBusGMainLoop

def notifications(bus, message):
    print(str(message))
DBusGMainLoop(set_as_default=True)

bus = dbus.SessionBus()
bus.add_match_string_non_blocking("eavesdrop=true, interface='org.freedesktop.Notifications', member='Notify'")
bus.add_message_filter(notifications)

mainloop = gi.repository.GLib.MainLoop()
mainloop.run()

似乎此代码只是从GLib返回对象

1 个答案:

答案 0 :(得分:0)

您在message中拥有的notification是不同的dbus.**.*Message实例,因此这就是打印出来的内容。

尝试for arg in message.get_args_list(): print(arg),您可能会找到想要的东西。