Ubuntu – How to temporarily filter-out certain notification-bubbles coming from specific sources


I have my system configured such that when I receive new mail, a notification balloon appears on my screen. This is convenient at times, and distracting at other times. Without having to uninstall the gmail integration I'm using, is there a way of centrally toggling whether certain kinds of notifications will be displayed?

In other words, I'm looking for an application (or API) which allows me to either see a list of "registered" apps that use the notification service, and toggle them as enabled/disabled. Or, something which allows me to create one or more regular expressions which can be used to match the source-application-name or notification-bubble-content, and if a match occurs, to block the notification.

Best Answer

... but it looks like a lot of work ...

It's not really too bad, at least for a crude generic solution.

Here is a copy of the details from my answer to last year's (sept 2012) post in

How to disable notification from network-manager.

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

Replace string "NetworkManager" with the desired RE to determine blocking.

To get an idea of what RE pattern match to look for run:
dbus-monitor "interface='org.freedesktop.Notifications'"
and look at the output while the notifications are popping-up.

ie. to remove notify-send messages also, use this grep line instead:

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

killall notify-osd is non-discriminating and completely wipes the notification stack of any pending messages irregardless of whether NetworkManager or notify-send is the notifying agent.

An "honest" solution needs to account for possible race conditions when between determining a notification purge is needed and then doing doing it, another notification comes in that should pop-up and not be purged with the rest.

Also, if notifications are pending when the offending one to be blocked comes in, they will all be purged. This situation can at least be solved by making a copy of the dbus pending notifications and then reissue the desired ones with notify-send after the purge.

This is a bit of manually labour intensive work!

Ideally, the direct dbus use of

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

to specifically target just the desired notifications, is unfortunately not obvious ... however ...

Another answer
Can org.freedesktop.Notifications.CloseNotification(uint id) be triggered and invoked via DBus?
shows how to use [1], at least with notify-send, but unfortunately not for arbitrary notifying aps. though some aps. have custom interfaces to control pop-up notifications.

cross refs.: