Ubuntu – Light Locker – Run script on screen lock/unlock

screen-lockxfcexubuntu

I'd like to run a script if the XFCE 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?

I have found following solutions:

for Gnome – Run script on screen lock/unlock

for xscreensaverHow do I run a script on unlock?

But I'm using light-locker and no screen saver. I was trying to monitor DBUS but it doesn't seem the light-locker emits any signals.

One option would be to modify xflock4 but that would help only with screen locking.

Is there any way for light-locker?

Best Answer

The previous answer helped me write this fragment of bash script that handles Lock and Unlock session events for the current session. I use it to suspend browser processes when the session is locked and to resume them when it unlocks. Tested under Debian unstable (Xfce 4.12) Enjoy!

session=/org/freedesktop/login1/session/$XDG_SESSION_ID
iface=org.freedesktop.login1.Session
dbus-monitor --system "type=signal,path=$session,interface=$iface" 2>/dev/null |
 while read signal stamp sender arrow dest rest; do
  case "$rest" in
    *Lock)
      echo   LOCKED at $stamp
      pause $@
;;
    *Unlock)
      echo UNLOCKED at $stamp
      resume $@
;;  #unknown Session signal received
    *)
#      echo $signal $stamp $sender $arrow $dest $rest
  esac
done
Related Question