Sunday, September 13, 2009

Suspend/Hibernate from command line

On a *NIX system, there are two main message buses: a system-wide one and one for each user session. The "dbus-send" command can send messages to either of the buses with --system or --session options along with a variety of options. Long story short, if you want to suspend or hibernate your machine, you need to send messages to org.gnome.PowerManager, not sure how it is for KDE systems. This is what your respective GUI options do internally.

To suspend, say:

$ dbus-send --session --dest=org.gnome.PowerManager --type=method_call --print-reply --reply-timeout=2000 /org/gnome/PowerManager org.gnome.PowerManager.Suspend

To hibernate, say:

$ dbus-send --session --dest=org.gnome.PowerManager --type=method_call --print-reply --reply-timeout=2000 /org/gnome/PowerManager org.gnome.PowerManager.Hibernate


  1. i had better luck with these (YMMV):

    dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Suspend

    dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Hibernate