Ubuntu Tip : lock and suspend keybinding

This keybinding method works for any commands in a string and most UI actions have command-line options - just a matter of finding them.

At work especially, I've finally got bored enough to fix this niggly problem, simpler suspend activation. Up to now I've done the usual thing: using the mouse to initiate suspend.  i.e. engage mouse, move it the top right power symbol, click, wait for the drop down menu, move mouse to "Suspend" and click it.  To save time I do it as quickly as possible, but very occasionally I have missed activating suspend, leaving my laptop without even a screenlock - leaving myself open to be "cheesed" by coworkers or worse.

So I wanted to find a method to lock the screen, then suspend the laptop from a few key presses.  I checked <Ctrl><Alt>S did nothing by trying it with the mouse pointer on the desktop background.  So far so good.  A bit of Googling and I found this:  http://ubuntuforums.org/showthread.php?t=813387&page=5 .  My work laptop is running Lucid but, there are methods for other versions in that excellent thread.

I've used gconf-editor to put in keybindings before, but I didn't remember where, so after a minute or so, gave up and went to use the Compiz settings gui.


First check the command you've chosed actually works.  Open up a terminal and run it.  For me it worked first time, YMMV, so tweak til it works.

Then on the desktop, select: System > Preferences > CompizConfig Settings Manager

Then navigate to: General > Commands

Then add your command locking then suspending (mine works for Lucid) to a Command:  gnome-screensaver-command --lock ;  dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

Now the command is added click on the "Key Bindings" tab and choose your keybinding. Click on the matching Run command # "Disabled" button, then tick "Enabled".  Then "Grab key combination" and hit your choices and then save with "OK"

You can test your key commands now outside this window to make your laptop lock and suspend.  When your happy, close the app.  That's it.