Going green… slightly

A simple thing but one that made me feel quite virtuous. I’ve written a very very simple script that turns off the screen whenever I lock the computer. Should save some energy every time I go to a meeting or off for a cuppa.

For anyone interested, it’s a Perl script which watches for the D-Bus signals from gnome-screensaver. Code is as follows:

my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";
open (IN, "$cmd |");
while (<in>) {
  if (m/^\s+boolean true/) {

Note that it relies you running Linux, using GNOME and there being a screen blanking script ‘/etc/acpi/screenblank.sh‘ (which in turn executes ‘/usr/share/acpi-support/screenblank‘ for every display). Not too much to ask I’m sure 🙂

— Edit 8th October 2008:
Since upgrading to Ubuntu Karmic, this script no longer seems to work for a couple of reasons. I’ve not investigated in any detail but I do have a new working script using a slightly different D-Bus signal and a different command to blank the screen. Try this if the one above doesn’t work!

my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'\"";
open (IN, "$cmd |");
while (<IN>) {
  if (m/^\s+boolean true/) {
    system('xset dpms force off')

3 thoughts on “Going green… slightly

  1. Nice. The <IN> in the while statement has got swallowed though, which might confuse some people.Also, on opensuse 11.2 with kde4, I had to use 'org.freedesktop.ScreenSaver' (along with ActiveChanged) instead of 'org.gnome.ScreenSaver'.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s