如何暂时过滤掉来自特定来源的某些通知气泡?

我配置了系统,以便在收到新邮件时,屏幕上会显示通知气球。 这有时很方便,而在其他时候会分散注意力。 无需卸载我正在使用的gmail集成,有没有办法集中切换是否会显示某些类型的通知?

换句话说,我正在寻找一个应用程序(或API),它允许我查看使用通知服务的“已注册”应用程序列表,并将它们切换为启用/禁用。 或者,允许我创建一个或多个正则表达式的东西,可用于匹配source-application-name或notification-bubble-content,如果匹配,则阻止通知。

您可以在d-bus级别对此进行过滤,但看起来很多工作。 首先看一下这篇文章,深入了解osd的运作方式

  • 使用DBus收听传入的libnotify通知

在单独的控制台上发送运行’notify-send’之前启动dbus-monitor。

方法调用sender =:1.2450  - > dest = org.freedesktop.DBus serial = 5 path = / org / freedesktop / DBus; 接口= org.freedesktop.DBus; 构件= GetNameOwner
   字符串“org.freedesktop.Notifications”
方法调用sender =:1.2450  - > dest =:1.41 serial = 6 path = / org / freedesktop / Notifications; 接口= org.freedesktop.Notifications; 构件= GetServerInformation
方法return sender =:1.41  - > dest =:1.2450 reply_serial = 6
   字符串“notify-osd”
   字符串“Canonical Ltd”
   字符串“1.0”
   字符串“1.1”
方法调用sender =:1.2450  - > dest =:1.41 serial = 7 path = / org / freedesktop / Notifications; 接口= org.freedesktop.Notifications; 构件=通知
   字符串“notify-send”
    uint32 0
   字符串“/usr/share/pixmaps/debian-logo.png”
   字符串“我的标题”
   字符串“一些文本正文”
   arrays[
    ]
   arrays[
       dict entry(
         字符串“紧急”
         变体字节1
       )
    ]
    int32 -1

notify-osd确实在dbus上运行

 dpkg -L notify-osd
 /usr/share/dbus-1/services/org.freedesktop.Notifications.service

但是在/etc/dbus-1/system.d中没有对此服务的附加限制

因此,您可以创建一个配置文件,该文件可以根据其来源过滤掉Notification事件,并实现您所追求的控制。 如果不深入研究问题和dbus规范,这是我能做的最好的事情。 我希望这会有所帮助,你所追求的应该更容易配置开始。

……但看起来很多工作……

这不是太糟糕,至少对于粗略的通用解决方案而言。

以下是我去年(2012年9月)的回答中的详细信息

如何禁用网络管理员的通知 。

dbus-monitor "interface='org.freedesktop.Notifications'" \ | grep --line-buffered 'string "NetworkManager"' \ | sed -u -e 's/.*/killall notify-osd/g' \ | bash 

string "NetworkManager"替换为所需的RE以确定阻止。

要了解RE模式匹配以查找运行:
dbus-monitor "interface='org.freedesktop.Notifications'"
并在通知弹出时查看输出。

即。 要删除notify-send消息,请改用以下grep行:

 | grep --line-buffered 'string "NetworkManager"\|string "notify-send"' \ 

警告
killall notify-osd是无差别的,并且无论NetworkManagernotify-send是否为通知代理,都会完全擦除任何待处理消息的通知堆栈。

一个“诚实”的解决方案需要考虑可能的竞争条件,在确定需要通知清除和然后执行之间时,另一个应该弹出的通知,而不是用其余的清除。

此外,如果要阻止的有问题的通知进入时通知处于待处理状态,则它们都将被清除。 这种情况至少可以通过复制dbus挂起通知来解决,然后在清除后通过notify-send重新发出所需的notify-send

这是一些人工劳动密集型工作!

理想情况下,直接使用dbus

 method void org.freedesktop.Notifications.CloseNotification(uint id) [1] 

特别针对所需的通知,遗憾的是不明显……但是…

另一个答案
可以通过DBus触发和调用org.freedesktop.Notifications.CloseNotification(uint id)吗?
显示如何使用[1] ,至少使用notify-send ,但遗憾的是不能用于任意通知aps。 虽然有些aps。 有自定义界面来控制弹出通知。

交叉参考:

  • 如何禁用网络管理员的通知
  • 是否可以阻止NotifyOSD用于一个应用程序?
  • 过滤消息到“通知区域”小程序
  • 如何自定义/禁用通知气泡?