I want to write a simple shell script that first sends out some info (possibly in a notification), then allows the user to toggle a switch or not, depending on the info.
I was thinking that it should be possible to execute a command when tapping a notification, but I can’t figure out how.
notificationtool has an Action option, which I suspect would allow me to do this:
-a, --action=ACTION An action for the notification in
"ACTIONNAME[;DISPLAYNAME] DBUSSERVICE DBUSPATH DBUSINTERFACE METHOD [ARGUMENTS]..."
format.
I have no idea how to implement any of this.
Can someone help?
This is much harder than I thought; I’m no good with all this Dbus stuff.
All I have is a little shell script, launched via .desktop launcher, that reads some values and sends a notification. Ideally I’d like to tap the notification to toggle that value, i.e. execute the same shell script again.
Could you help me with formulating that (the .desktop launcher and the Action for the notification)?
Lots of commented stuff from some unrelated experiments.
And the script itself:
#!/bin/ash
me="${0##*/}"
# dependency checks
for dep in mcetool notificationtool; do
command -V $dep >/dev/null || exit 1
done
if [ "$1" = toggle ]; then
do something
exit
fi
data="$(mcetool |grep -E ^'Charging|Battery level|Battery state')"
head="${data%%$'\n'*}"
data="${data#*$'\n'}"
notificationtool -o add -c x-nemo.battery -a "dosomething a a a exec charging-toggle toggle" "$head" "$data"