Skip to main content
2 of 4
added 381 characters in body
peoro
  • 4k
  • 3
  • 35
  • 32

gnome-screensaver emits some signals on dbus when something happens.

Here the documentation (with some examples).

You could write a scripts that runs:

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'"

and that does what you need anytime dbus-monitor prints a line about the screen locked/unlocked.


Here a bash command to do what you need:

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | ( while true; do read X; if echo $X | grep "boolean true" &> /dev/null; then SCREEN_LOCKED; elif echo $X | grep "boolean false" &> /dev/null; then SCREEN_UNLOCKED; fi done )

Just replace SCREEN_LOCKED and SCREEN_UNLOCKED with what you need.

peoro
  • 4k
  • 3
  • 35
  • 32