1

I want to display my desktop notifications (I'm using Gnome 3) on some other device. So I want to write a software that gets the notification on my computer and sends it over the internet. Unfortunately, I didn't find any good point to start on how my code can get the notifications and do something with them.

Is there some API for it?

  • This is a little confusing for me. Are you asking about how to change the location of gnome notifications or just how to send desktop notification from your own programs? (or both?) – grochmal Aug 21 '16 at 19:39
  • @grochmal I clarified it. I want to write a software that reads the notifications on my computer and sends them via network to some other device. – Florian Aug 21 '16 at 23:40
2

Well, Gnome notifications use D-BUS to pass the messages around. The gnome specification describes how to use the org.freedesktop.Notifications.* classes and has a good deal of formatting tips. In general it is a HTML-ish format.

Yet, you absolutely cannot talk to the D-BUS on another machine remotely. Let's not even start on how many security holes that would open.

Still, you can always have a program on the target machine that will receive the communication and talk to D-BUS locally already in there.

There are two options that are wrappers around org.freedesktop.Notifications.* and make writing programs much easier:

  • libnotify: which is almost a de-facto standard for making notifications, supports not only gnome but several others.

  • notify-sharp-3: as strange as it may sound it is an open-source C# based functionality around several notification specs. At some point it even had its own language called boo, but it is kind of dying out in favour of libnotify.

OK, libnotify we go.

libnotify comes with a binary that knows how to talk with the notification daemon (yes, those notifications are displayed by a background daemon). The command is notify-send, and it is rather trivial to use.

notify-send 'Meeting in 5 minutes' 'John from the <b>QA Team</b> just found a bug that should never had happened.  Seriously, we are doing something wrong'

And that will display the notification. Yet, making it remote is a little more complex. Assuming that you know that bob is the user currently running Xorg at machine krakatoa and that krakatoa has libnotify installed and is running gnome notify daemon you can do:

ssh bob@krakatoa \
    notify-send 'Meeting in 5 minutes' \
    'John from the <b>QA Team</b> just found a bug that should never had happened.  Seriously, we are doing something wrong'

But finding each user on each machine may be tricky. You may try to create a script that will perform ps -afe | grep gnome, find the user and run su -u <user> DISPLAY=:0 notify-send .... But then again, you probably should not send ssh requests as root in the first place.

The Arch wiki has a list of interfaces to libnotify in several languages. From there you can create your own daemon, with your own communication protocol for the notification messages. For example, since you are specifically after gnome, python Gobject may just fit the bill.

In summary:

  • Notifications happen on D-BUS;

  • You cannot directly access D-BUS remotely;

  • You can use libnotify to access D-BUS from a program under your control on the target machine.

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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