gnome-power-cmd is dead, long live dbus-send?

The new Karmic is missing something that I used to use: gnome-power-cmd (formally gnome-power-cmd.sh). To fill this void, I had to dive into the internet to find what could replace it.

The idea behind gnome-power-cmd is that you could make suspend, hibernate and reboot calls from the commandline if you where logged in as normal user, not needing the root privileges. It was a userspace variant of the pm-utils (pm-suspend, etc.) which all need you to be root. The death of the command (which was simply a shell script) probably came with the HAL to DeviceKit transition. So, on Karmic it seems that neither HAL dbus messages, nor gnome-power-command calls will work. This is the closest thing I could find:

dbus-send --print-reply \
            --system \
            --dest=org.freedesktop.DeviceKit.Power \
            /org/freedesktop/DeviceKit/Power \
            org.freedesktop.DeviceKit.Power.Suspend

That should suspend your computer. You can substitute the Suspend with Hibernate if you want, although I haven't tried the latter as it doesn't work with my computer (on boot, it just ignores it and nothing is restored). A local replacement for gnome-power-cmd shown and downloadable below

The script below has also been attached so you don't have to copy paste it if you don't want to.

#!/bin/bash
#    gnome-power-cmd replacement
#    Copyright (C) 2009 A. Bram Neijt <bram@neijt.nl>
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

case $1 in
suspend)
echo Suspending
    dbus-send --print-reply \
        --system \
        --dest=org.freedesktop.DeviceKit.Power \
        /org/freedesktop/DeviceKit/Power \
        org.freedesktop.DeviceKit.Power.Suspend
;;
hibernate)
echo Hibernating
    dbus-send --print-reply \
        --system \
        --dest=org.freedesktop.DeviceKit.Power \
        /org/freedesktop/DeviceKit/Power \
        org.freedesktop.DeviceKit.Power.Hibernate
;;
*)
echo Not supported command: '"'$1'"'
echo Usage: $0 '<suspend|hibernate>'
exit 1
;;
esac

AttachmentSize
gnome-power-cmd.tgz760 bytes

Comments

thanks a lot

It's a pity that Canonical didn't replace the file and break the "interface". Personally I didn't care if I use HAL or DeviceKit to call the suspend command from User space.
I used it to send my computer after a time period to sleep , so I can listen to audiobooks at nights.
Thanks for the script

Nico

gshutdown is also an option

If you use a timer, you can also use gshutdown (sudo aptitude install gshutdown). It's a program that can shutdown using a timer.

But if you have a large job running for "some" time, you still have to use the command-line to shutdown after.

Thank you!

Works like a charm.

Your solution works like a

Your solution works like a charm, thank you!

Quite useful

I get here looking for exactly that, a replace on gnome--power-cmd. It's sad how some things have only graphical interfaces and no equivalent commandline.

Thank you so much