23 Nov 2012, 18:13

How to lock xscreensaver on suspend

I’m running Fedora 17 with Gnome3 and xscreensaver. One small problem I had is that resuming from suspend did not automatically lock the screen. Thanks to a helpful post on askubuntu.com, came up with this solution:

  • Create file /etc/pm/sleep.d/10-xscreensaver containing the following:
#!/bin/bash
case "$1" in
suspend)
export DISPLAY=":0"
su myuser -c "(xscreensaver-command -lock)"
;;
*)
;;
esac
  • Replace ‘myuser’ with your username. You may also need to adjust the DISPLAY variable depending on your screen setup ( ‘:0’ should work for most setups)
  • make the script executable: chmod +x /etc/pm/sleep.d/10-xscreensaver

  • On my Dell Optiplex 790 workstation, I can now hit the power button and the computer goes to sleep. Upon resume, I have a locked screen