Tech Tip: Go Green On Your Screen(saver)

October 20th, 2009 by Sangeeth Keeriyadath in

Your rating: None Average: 4.7 (15 votes)

I usually lock my screen when I leave my cubicle for a tea-break etc. With all the talk of saving energy these days I've disabled screen-savers on my system. Still, when I'd lock my screen I noticed that the LCD didn't turn off completely. Wanting to go as green as I could I wanted to switch off the LCD as well.

The following command does that:

  xset dpms force off

When I press "Alt+Ctrl+L" (lock screen), the following command is invoked:

  gnome-screensaver-command --lock

What I want now is to associate the following command with a different shortcut key:

   gnome-screensaver-command --lock; xset dpms force off

So that I can lock as well as power off my LCD screen with a keyboard shortcut. To do this I installed xbindkeys to add a custom shortcut key. When you have xbindkeys installed create created the default config file:

  xbindkeys --defaults > /home/your-user-name/.xbindkeysrc

Now assign a shortcut key. To do this you edit the config file (or if you prefer you can install xbindkeys-config) and append the following lines to the file:

# lock&blank
"gnome-screensaver-command --lock; sleep 1; xset dpms force off;"
alt+control+k

You also should remove all the enabled lines (comment them out), at least in my case they somehow interfered with my other shortcuts. I also had to add the sleep 1 between the commands to get it to work, perhaps due to compiz animation time.

Now, when I press "alt+control+k" I save power as well as lock my screen.

Tested on Ubuntu 8.10 running on Lenovo T61p.

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

1. They consume more power than a switched off display(the calculation for this is pretty simple :) )
2. screensavers do consume some amount of CPU cycles.
3. Keeping the display switched on continuously may reduce it's lifetime.

__________________________

Sangeeth Keeriyadath
www.sangeek.com

Mitch Frazier's picture

KDE

On October 26th, 2009 Mitch Frazier says:

For KDE do:

dcop kdesktop KScreensaverIface lock
sleep 1
xset dpms force off
__________________________

Mitch Frazier is an Associate Editor for Linux Journal and the Web Editor for linuxjournal.com.

Antonio's picture

> For KDE do: > dcop

On October 31st, 2009 Antonio (not verified) says:

> For KDE do:
> dcop kdesktop KScreensaverIface lock
> sleep 1
> xset dpms force off

NOOO

Since years ago KDE uses D-Bus, so it should be:
qdbus org.kde.krunner /ScreenSaver org.freedesktop.ScreenSaver.Lock; sleep 2s; xset dpms force off

See more in:
http://foss-boss.blogspot.com/2008/11/ride-d-bus-control-your-linux-desktop.html

If you're using KDE4 then yes, use dbus. If you're using KDE3, which I am, then no, use dcop. I should have mentioned that this was for KDE3.

__________________________

Mitch Frazier is an Associate Editor for Linux Journal and the Web Editor for linuxjournal.com.

Mark Pettit's picture

works in XFCE too

On October 21st, 2009 Mark Pettit (not verified) says:

Very neat. I also used the xscreensaver-command -lock;sleep 1;xset dpms force off, saving it into a text file, making it executable, and then configuring that as
a hot-key under XFCE (used linux-key + L). and blow me down, it worked.
Thanks

lowtech's picture

I just plugged my lcd's into

On October 21st, 2009 lowtech (not verified) says:

I just plugged my lcd's into a powerstrip on the desktop. and then jut hit that button. :)

Anonymous's picture

May need to disable gnome-power-manager's backlight handling

On October 20th, 2009 Anonymous (not verified) says:

Because the current gnome-power-manager's backlight control is completely broken, you may need to disable it by setting /apps/gnome-power-manager/backlight/enable to false in gconf-editor. At least on my laptop gpm kept turning the backlight back on after a minute or so after running xset dpms force off.

ngine13's picture

You just need to set

On November 16th, 2009 ngine13 (not verified) says:

You just need to set /apps/gnome-power-manager/backlight/idle_brightness to 0. I tested it and works so far. :)

ngine13's picture

No i'm wrong.. :(

On November 16th, 2009 ngine13 (not verified) says:

No i'm wrong.. :(

Anonymous's picture

it works with xscreensaver too

On October 20th, 2009 Anonymous (not verified) says:

the same tip can also be done if you use xscreensaver instead of gnome's
even doing $xscreensaver-command -lock; sleep 1; xset dpms force off in a terminal works
I also was looking for a way to turn off my laptop's screen so thanks for the tip :)

ngine13's picture

You can assign the shortcut

On November 16th, 2009 ngine13 (not verified) says:

You can assign the shortcut key using "Commands" in CompizConfig Settings Manager (in Gnome).

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.


Read this issue