18

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.

4
  • 1
    Unlike Gnome-Shell notification, On Ubuntu application does not registered in notification service. It uses libnotify for notification which is hard-coded in applications. You can try switch off notification from application preference if it has a notification preference(like gwibber, evolution, thunderbird etc). Jul 5, 2013 at 10:59
  • 1
  • @orschiro This is not a duplicate of the (recently posted) question you referred to -- this question is about being able to programmatically filter only certain kinds of notifications, while allowing others through. The other question is specifically about muting all notifications.
    – Mark
    Jul 25, 2016 at 19:11
  • Oh, you're right. I have missed this on a first glance. Thank you!
    – orschiro
    Jul 25, 2016 at 20:43

2 Answers 2

5

... 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"'  \

Caveat:
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.:

2

You may be able to filter this at the d-bus level, but it looks like a lot of work. First see this post to get insight into how osd operates

Start up dbus-monitor before you send the run 'notify-send' on a separate console.

method call sender=:1.2450 -> dest=org.freedesktop.DBus serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetNameOwner
   string "org.freedesktop.Notifications"
method call sender=:1.2450 -> dest=:1.41 serial=6 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications; member=GetServerInformation
method return sender=:1.41 -> dest=:1.2450 reply_serial=6
   string "notify-osd"
   string "Canonical Ltd"
   string "1.0"
   string "1.1"
method call sender=:1.2450 -> dest=:1.41 serial=7 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications; member=Notify
   string "notify-send"
   uint32 0
   string "/usr/share/pixmaps/debian-logo.png"
   string "My Title"
   string "Some text body"
   array [
   ]
   array [
      dict entry(
         string "urgency"
         variant             byte 1
      )
   ]
   int32 -1

notify-osd does live on dbus

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

but there's no additional constraints for this service in /etc/dbus-1/system.d

So you might be able to make a config file that can filter out Notification events based on their source and achieve the control you're after. That's the best I can do without digging into the problem and the dbus spec. I hope this helps, what you're after should be easier to configure to begin with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.