2

Can libnotify be used to execute a script?

I want to use a script to play a sound, or even run more complicated programs via the notify-send in bash files and other programs.

Is that possible? It seems to use only popups?

2

You're close, you don't actually want to run a script on libnotify but rather create a monitor against the event that is triggering to cause the notification. You may even be able to trigger on the actual message being sent by notify-send, but I have not tried that directly, so cannot confirm.

NOTE: libnotify can only produce the messages via notify-send from what I've been able to find in my searches.

To monitor for an event you use dbus-monitor. A sample script could be constructed like so:

excerpt from How to continuously monitor rhythmbox for track change using bash

#!/bin/bash

interface=org.gnome.Rhythmbox.Player
member=playingUriChanged

# listen for playingUriChanged DBus events,
# each time we enter the loop, we just got an event
# so handle the event, e.g. by printing the artist and title
# see rhythmbox-client --print-playing-format for more output options

dbus-monitor --profile "interface='$interface',member='$member'" |
while read -r line; do
    printf "Now playing: "
    rhythmbox-client --print-playing
done

The above watches the org.gnome.Rhythmbox.Player interface watching for the member playingUriChanged to be called. When it is the result is read by the read command with the contents being stored into the variable line.

The contents of line are actually not used within, just to collect the results from dbus-monitor. The results within the while loop would print the output like so:

Now playing: Daft Punk - Overture
Now playing: Daft Punk - The Grid

The names of the songs are being produced from rythmbox-client --print-playing.

Determining a DBUS signal/event

You can consult these 2 Q&A's for further details on how to accomplish this:

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.