【问题标题】:Is there any way to read Linux Desktop Notification with Python?有没有办法用 Python 读取 Linux 桌面通知?
【发布时间】:2019-12-29 04:41:33
【问题描述】:

我需要使用 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 中返回对象

【问题讨论】:

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


    【解决方案1】:

    notification 中的 message 是不同的 dbus.**.*Message 实例,所以这就是打印出来的内容。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-20
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      相关资源
      最近更新 更多