My problem is the same of this question but I am not able to get it working in ubuntu 17.10:
How to run a command or script at screen lock/unlock?
I want to run a script that changes my keyboard RGB configuration at screen locks. The script runs flawless. The problem is to get the event of the locking/unlocking. I have try using dbus-monitor as said in that question and as said here:
https://people.gnome.org/~mccann/gnome-screensaver/docs/gnome-screensaver.html
So running this script:
#!/bin/bash
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | \
( while true
do read X
if echo $X | grep "boolean true" &> /dev/null; then
echo "locking at $(date)" >> $HOME/time_xprofile
elif echo $X | grep "boolean false" &> /dev/null; then
echo "unlocking at $(date)" >> $HOME/time_xprofile
fi
done )
But it only works... a few times(!).... I cannot understand what happens.
I'm using ubuntu 17.10 with ubuntu's gnome over X-server (no Wayland) and have try vanilla gnome and have the same problem.
I have try too:
dbus-monitor > out.log
To see ALL the traces that occur while locking/unlocking and it doesn't appear that signal... Only.... well... very few times...
I don't know what to do know, Any advice will be helpfull.
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'"
, does it toggle true/false on lock/unlock?pgrep -f gnome-screensaver
, and subsequently:sleep 10 && pgrep -f gnome-screensaver
, immediately lock screen, wait10-15 seconds and then unlock again. On my system[1]
shows one pid,[2]
shows two pids. That would be something to work with. If dbus is no option.