Monday, December 26, 2005

Howto turn off your monitor when you lock your screen

I wanted to turn off my monitor when I lock my screen. Now, I use xfce, and the (default) shortcut to lock your screen in xfce is ctrl+alt+del

I have a habbit of pressing ctrl+alt+del when I leave the PC for a few minutes, and I thought it would be nice if I could turn off the monitor simultaneously. So here's what I did.

xfce runs the "xflock4" script to lock the screen. So open the script in a text editor
sudo gedit /usr/bin/xflock4

Now add this line before "exit 0"
xset dpms force off

So basically, your file will look like this:


#!/bin/sh
#
# xfce4
#
# Copyright (C) 1999, 2003 Olivier Fourdan (fourdan@xfce.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

xscreensaver-command -lock || xlock $*
xset dpms force off
exit 0


The disadvantage is that if your mouse moves, or any key is pressed, the monitor won't turn off again, but I can live with that :)

Please feel free to leave comments and suggestions.

Again, do this at your own risk, and don't forget to make a backup.

No comments: