You need to enable JavaScript to run this app. 如何在dbus-monitor中检测通知发送方与目标地址、解决通知重复问题
优惠活动
大模型
产品
解决方案
定价
更多

如何在dbus-monitor中检测通知发送方与目标地址、解决通知重复问题

D-Bus通知过滤脚本的使用问题

当前的实现与故障现象

我的目标是过滤来自不同应用(主要是不同浏览器窗口)的通知。
我发现可以借助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.56,随后:1.56会作为中转发送方,把同一条消息再转发到最终目标地址:1.40——上述测试仅通过notify-send hello发送了一条测试消息,却在日志里被记录为两条。

目前脚本可以正常运行,但每次系统启动后,D-Bus动态分配的目标地址编号会发生变化,我都需要手动查询最新的目标地址编号,再修改脚本配置才能生效。

待解决的两个问题

  • 如何自动获取上述最终接收通知的目标地址字符串(示例中的:1.40)?
  • 如何从根源上避免系统重复发送同一条通知?如果能解决第二个问题,自动获取地址的需求也就不存在了。

内容的提问来源于stack exchange,提问作者mila

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.06 08:15:05