Skip to content

Instantly share code, notes, and snippets.

@rduplain
Created October 8, 2012 15:02
Show Gist options
  • Save rduplain/3852987 to your computer and use it in GitHub Desktop.
Save rduplain/3852987 to your computer and use it in GitHub Desktop.
Watch xscreensaver lock/unlock events and act on them.
#!/bin/sh
# Watch xscreensaver and react to status changes.
#
# Replaced my previous perl-based recipe with this:
# http://semicomplete.googlecode.com/svn/tools/xscreensaver-watch.sh
#
# Include somewhere in X session startup with:
#
# xscreensaver-watch &
lock() {
# Log this somewhere with `date` instead of just echoing.
echo `uname -n` screen is now blank
# Do other things here, like stop music playback & mute speakers.
}
unlock() {
# Log this somewhere with `date` instead of just echoing.
echo `uname -n` screen is now unblank
# Do other things here, like resume music playback & unmute speakers.
}
xscreensaver-command -watch | while read a; do
echo "$a" | grep -q '^LOCK' && lock
echo "$a" | grep -q '^UNBLANK' && unlock
done
@dimm0k
Copy link

dimm0k commented Nov 16, 2016

thanks, great code! I was looking for this to reset my HDMI audio/video driver after the monitor goes to sleep!

@niclet
Copy link

niclet commented Jan 27, 2019

On my raspberry, lock occurs with '^BLANK' keyword.
Now my touchscreen goes really to sleep.
Thanks

@JoshuaJChan
Copy link

sick!!! I was looking for this all day. Now I can use i3lock to substitute xscreensaver's crusty login screen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment