Sunday, October 10, 2010

Suspend shortcut on Ubuntu Gnome panel

Admittedly, the default Gnome panel setup on Ubuntu Lucid is rather sleek and utilitarian, alas there are some who would like to suspend to RAM in one click not two. The screen will be locked upon resuming, better safe than sorry right?

1. Create a file named suspend.sh with the following content:

#!/bin/bash
gnome-screensaver-command --lock
dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

2. You may need to

chmod 755 suspend.sh

3. Right-click Gnome top panel and 'Add to panel...'

4. Create a new launcher.

5. Select the following launcher properties:

Type: Application in Terminal
Name: Suspend
Command: /point/to/suspend.sh

6. Choose an appropriate icon like e.g. /usr/share/icons/hicolor/48x48/apps/gdu-hba.png , yeah I know that's not what an off-button looks like. It's close, give me that.