Xmonad idle lock after X minutes

Using Ubuntu 10.10. I use XMonad window manager as primary. I have CommandKey+S mapped to a bash file that shows a screensaver and locks, and puts the PC to sleep (on resume I have to enter password).

#/bin/bash

gnome-screensaver-command -a
gnome-screensaver-command -l
dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

This works fine. However I'd like XMonad to automatically run that script (i.e. lock screen and suspend) after X minutes of no keyboard/mouse activity.

I've taken it (basic screensaver/lock/suspend) for granted in other desktops/windows managers.


You can use xautolock to do this. For example,

xautolock -time 1 -locker "gnome-screensaver-command -l" -notify 10 \
  -notifier "notify-send -t 5000 -i gtk-dialog-info 'Locking in 10 seconds'"

This will lock your screen after 1 minute of idle time and will give you a notification (lasting 5 seconds) 10 seconds before it locks. This works fine for me in Xmonad.

To use notify-send you may need to

sudo apt-get install libnotify-bin

or something like that. I'm sure you could also substitute out gnome-screensaver for xscreensaver or something else.