I am using a simple dbus-monitor script for gnote. The script starts when gnote starts. I modified exec
parameter of desktop file to achieve this.
The problem is that I didn't find any way to kill my script after the application(i.e gnote) exits. If the application itself exits there is no point to keep script running in the background as it is not going to fetch any output.
The script looks like this:
#!/bin/bash
OJECT="'org.gnome.Gnote'"
IFACE="'org.gnome.Gnote.RemoteControl'"
DPATH="'/org/gnome/Gnote/RemoteControl'"
echo $IFACE
WATCH1="type='signal',sender=${OJECT},interface=${IFACE},path=${DPATH},member='NoteAdded'"
WATCH2="type='signal',sender=${OJECT},interface=${IFACE},path=${DPATH},member='NoteSaved'"
WATCH3="type='signal', sender=${OJECT}, interface=${IFACE}, path=${DPATH}, member='NoteDeleted'"
dbus-monitor ${WATCH2} |
while read LINE; do
echo $LINE | grep "note://"
done
I tried to modify it like this :
dbus-monitor ${WATCH2} |
while read LINE; do
echo $LINE | grep "note://"
if pgrep "gnote" > /dev/null; then
echo ""
else
break;
fi
done
pid=`pidof -x $(basename $0)`
kill $pid
But it didn't work. I also tried using trap
as explained in this question but without success.