My pretty face [ László Monda's Blog ]
Exploring the cyberspace, one quadrant at a time!

Lock your laptop and turn off display with the touch of a keystroke in Ubuntu Karmic

I think this feature will soon be standard in Ubuntu as many users requested it. It's absolutely mandatory for me because every time I leave my laptop I carry out this action, even at home. Yeah, call me paranoid...

I've written a simple script to deal with the issue:

0
1
2
3
#!/bin/bash
gnome-screensaver-command -l
sleep 3
xset -display :0.0 dpms force off

You're encouraged to bind it to any key combo. It should work perfectly out of the box but a gnome-power-manager related bug enables the display some seconds or minutes later randomly, so we have to

0
killall gnome-power-manager

and it should be pretty fine. For those who can't afford to live without gnome-power-manager an alternative (and in my opinion suboptimal) workaround exists.

5 Responses to “Lock your laptop and turn off display with the touch of a keystroke in Ubuntu Karmic”

  1. Pablo says:

    Hi Lazlo! I've been using your script and followed your sugestions, except for removing gnome-power-manager or killing it.

    However, I think I've found a (quite simple) workaround for this (so called) "bug" (which now I'm not really sure it is so)... just increase the number of seconds to sleep to, lets say... 5.

    So, my script goes like this:

    #!/bin/bash
    gnome-screensaver-command -l
    sleep 5
    xset -display :0.0 dpms force off

    Now, everything works just fine! :)

    For those of you who don't want to lock the screen, I would recommend to sleep 1 sec before executing xset (otherwise it won't work). So, this second script would include the following lines:

    #!/bin/bash
    sleep 1
    xset -display :0.0 dpms force off

    Apparently, it might be that clicking or moving the mouse or maybe pressing the key combo, sends later events... that's why, Linux first needs some time to deal with those before you can successfully call xset.

    Hope this helps you all in my same situation!

    Greetings from Argentina! Pablo.

  2. Laci says:

    Hey Pablo,

    I've just tried your method of waiting 5s instead of 3s and it didn't work. You may be using an upgraded version of gnome-power-manager which doesn't have this bug. Anyways, I'll update to 10.10 soon and hopefully this problem will get solved.

  3. michael says:

    For those who use xscreensaver, you can get around locking the screen and disabling gnome-power-manager by just using:

    xscreensaver-command -activate
    sleep 0
    xset dpms force off

    the sleep 0 is probably not even necessary.

  4. michael says:

    spoke to soon, that doesn't work either. you still have to disable gnome-power-manager

  5. Laci says:

    Thanks for trying another workaround, Michael. Yeah, this bug is quite nasty and there is no workaround except killing gnome-power-manager.

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">