4

我的目标是过滤来自不同应用程序的通知(主要来自不同的浏览器窗口)。

我发现在 dbus-monitor 的帮助下,我可以编写一个小脚本来过滤我感兴趣的通知消息。过滤器脚本运行良好,但我有一个小问题:

我从

dbus-monitor "interface='org.freedesktop.Notifications', destination=':1.40'"

命令。我必须添加“destination=':1.40'”,因为在 Ubuntu 20.04 上,我总是收到两次相同的通知。以下输出

dbus-monitor --profile "interface='org.freedesktop.Notifications'"

证明原因:

type   timestamp               serial  sender  destination     path                            interface               member
#                                       in_reply_to
mc      1612194356.476927       7       :1.227  :1.56   /org/freedesktop/Notifications  org.freedesktop.Notifications   Notify
mc      1612194356.483161       188     :1.56   :1.40   /org/freedesktop/Notifications  org.freedesktop.Notifications   Notify

正如您所看到的,发件人 :1.277 首先发送到 :1.56,这将是发件人到 :1.40 的目的地。(只是notify-send hello发送了测试消息)

我的脚本正在以这种方式工作,但是每次系统启动时,我都必须检查目标号码并相应地修改我的脚本才能正常工作。

我有两个问题:

  1. 如何自动发现目标字符串?(上例中为:1.40)
  2. 如何防止系统两次发送相同的消息?(如果这个问题能得到回答,那么第 1 点下的问题就变得毫无意义了。)
4

0 回答 0