I'd like to run a script if the Gnome session is locked and unlocked.
Is there a way that I can intercept this and perform certain actions when the desktop is locked or unlocked?
Linux X11 GNOME – How to Run a Script on Screen Lock/Unlock?
gnomelinuxx11
Best Answer
Gnome-screensaver emits some signals on dbus when something happens.
Here the documentation (with some examples).
You could write a scripts that runs:
and that does what you need anytime
dbus-monitor
prints a line about the screen being locked/unlocked.Here a bash command to do what you need:
Just replace
echo SCREEN_LOCKED
andecho SCREEN_UNLOCKED
with what you need.