Use (and identify) notifications to trigger subsequent actions
If we edit the proposed snippet in this very nice answer a bit, we can write the called notification to a file:
dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "string" | grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v | grep --line-buffered '.*(?=string)|(?<=string).*' -oPi | grep --line-buffered -v '^\s*$' | xargs -I '{}' echo {} > file.txt
or otherwise use it to trigger subsequent actions.
An example
If we edit the snippet to run a script when a notification pops up:
dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "string" | grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v | grep --line-buffered '.*(?=string)|(?<=string).*' -oPi | grep --line-buffered -v '^\s*$' | xargs -I '{}' /bin/bash /path/to/script.sh {}
and script.sh
is:
#!/bin/bash
string=$1
match="een aap op een fiets"
if [[ $string == $match ]]
then
gedit
fi
Then, every time, if the notification matches "een aap op een fiets":

gedit
will open :)

Note
Although the code works perfectly to intercept the notification to trigger any kind of action, I found no way to identify the pid
that called the notification.
dbus-monitor "interface='org.freedesktop.Notifications'" | grep --line-buffered "string" | grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v | grep --line-buffered '.*(?=string)|(?<=string).*' -oPi | grep --line-buffered -v '^\s*$' | xargs -I '{}' echo {} > file.txt
we can write the notifications to (e.g.) a file or do anything else with it, like triggering an action if the message contains or matches a certain string. I don't see any options for catching the pid which sent the message however, but it might be worth looking into. – Jacob Vlijm Nov 13 '15 at 18:59