June 03, 2008

Turning off display in KDE

Kubuntu Gutsy has a bug that prevents screensaver from starting automatically in KDE. It is supposed to be fixed in the next version (Hardy). However, I am still running Gutsy and I cannot upgrade until my employer officially supports Hardy. I never shut down my laptop. After I go to sleep it keeps running with its LCD turned on for the entire night. This wastes energy unnecessarily. With some reading here and there, I wrote a shell script that will do exactly what I want to do before I go to sleep: lock the screen and turn off the LCD display. The script itself is very simple:
# Locks screen and turns off display power.
# CAVEAT: Works only with KDE.

sleep 1                         # Wait for a second to let the user
                                # takes hand off keyboard.
xset dpms force standby         # This switches off the display.
exec kdesktop_lock --forcelock  # This locks the screen.
Now I have bound script to Ctrl+Alt+L key, which by default locks the screen. Whenever I step away from the computer, I can press Ctrl+Alt+L and it will turn off the monitor in addition to locking the screen :) PS: For information on how to assign shortcut keys to arbitrary commands/scripts, see this old post of mine.

1 comment: