Topic: [Solved] Adding a Shutdown option to menu.xml

Greetings all,
As I have come to love OpenBox while using #!, I have started using it as my WM of choice in Arch.  I am trying to add a shutdown option to my menu so that like in #!, I can select "shutdown" and the computer properly shuts down.
I added this line to my menu.xml file

<item label="Shutdown">
<action name="Execute">
<execute>shutdown -h now</execute>
</action>
</item>

When I reconfigured Openbox the "Shutdown" showed up in my menu.  But when I click it, nothing happens.  Now I know I can still open up terminal and as root type shutdown -h now and shutdown that way but what am I doing wrong in my menu.xml to now allow this to work.  Could it be that when I select the option in the menu; it does nothing because I am not "root"?

Thank you in advance for any and all assistance.

Ian

Last edited by ichase (2011-04-27 18:24:41)

Re: [Solved] Adding a Shutdown option to menu.xml

Yes you need to edit your sudoers file so you can use shutdown without a password

sudo visudo

and at the end, add this:

ALL     ALL=NOPASSWD:/sbin/shutdown

Good luck ...

.signature

Re: [Solved] Adding a Shutdown option to menu.xml

Thanks for the response d2ogch3n but I do not use Sudo unless I am using a distro that already has it installed and running.  I perfer to "su" to root and do what I need to do.  As I am the only user on my machines, I do not see a need to install Sudo.  smile  It's just personal preference.  smile

Ian

Re: [Solved] Adding a Shutdown option to menu.xml

ichase wrote:

Could it be that when I select the option in the menu; it does nothing because I am not "root"?

I think that's it. You could try 'gksu shutdown -h now' which would popup a window to enter your password. Alternatively, try this (long) line in menu.xml instead of 'shutdown -h now' :

dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
John
------------------------
( a boring Japan blog , and idle twitterings )
“Good morning sir, which way up would you like your reality today?”  "As it comes, Jeeves, as it comes..."

Re: [Solved] Adding a Shutdown option to menu.xml

Thanks John,
I will give that a try.  wink

All the best,

Ian

Edit:  John, adding that long string to my menu.xml in place of shutdown -h now worked like a champ!!!!  Thanks again.

Last edited by ichase (2011-04-27 17:12:16)

Re: [Solved] Adding a Shutdown option to menu.xml

groupadd shutdown
usermod -G shutdown $USERNAME
chgrp shutdown /sbin/shutdown
chmod g+x /sbin/shutdown
chmod +s /sbin/shutdown
ln -s /sbin/shutdown /bin/shutdown

Then your menu code should work as written.

Oops, I see a hal solution has been posted.  Will post this anyway since hal has been deprecated.

Last edited by tranche (2011-04-27 17:40:10)

Re: [Solved] Adding a Shutdown option to menu.xml

Super+X brings up the default Crunchbang logout which is a script that's called openbox-logout. If you look into the script, you'll find that

gdm-control --shutdown && openbox --exit

shuts your computer down.
So putting that row in the menu would do the the shutdown the same way as the "normal" Crunchbang logout script.

Last edited by GuruX (2011-04-27 17:45:07)

Re: [Solved] Adding a Shutdown option to menu.xml

Makes me wonder why this is this way. It should be something for superusers to shutdown machines, so there shutdown is protected. Wouldn't it make sense to make shutdown available for normal users for distributions aimed for desktop use?

And what is the point of hiding shutdown when any user can send gdm-control --shutdown && openbox --exit? And, killall gdm is prohibited from aa tty?

And this funny dbus command... Can't that be sent from any machine? Or any machine that has X running?

I smell some inconsistent behavior here. Mostly there's a good reason for everything on our beloved system, that's why I'm curious for what you think.

As a concrete proposal: Why not add d2ogch3n's line to Waldorf's sudoers:

ALL     ALL=NOPASSWD:/sbin/shutdown

Re: [Solved] Adding a Shutdown option to menu.xml

Well, I probably do need to come up with another option because I do use menumaker.  When I have added a few programs I normally issue the command mmaker -vf OpenBox3  this finds all executable programs and re-writes your menu.xml file.  Which in turn would more than likely remove the Shutdown and now Reboot options I added to the current menu.xml file.  smile

I probably just need to get comfortable editing the file myself and not depend on another program to do it for me.  wink

GuruX - I think I read that && is not recogized in xml.  I could very well be wrong.

All the best,

Ian

Re: [Solved] Adding a Shutdown option to menu.xml

^
Just tried. You are right. So the simple solution then would be to put that line in a script instead and run the script from the Openbox menu.

edit: only gdm-control --shutdown won't shut down your system. you need to exit openbox aswell.

Last edited by GuruX (2011-04-29 15:32:26)

Re: [Solved] Adding a Shutdown option to menu.xml

I don't think it's so much that && isn't xml compliant (actually you'd have to use &amp;&amp;) so much as that openbox's menu doesn't accept any shell stuff (except ~/). All you can put in menu.xml is a command + arguments, so you'd indeed have to use a script for anything more than that.

John
------------------------
( a boring Japan blog , and idle twitterings )
“Good morning sir, which way up would you like your reality today?”  "As it comes, Jeeves, as it comes..."

Re: [Solved] Adding a Shutdown option to menu.xml

I recommend using hal/dbus rules.   You can actually hack openbox-logout to use these instead, if the hacked openbox-logout is in your ~/bin folder it will overlay /usr/bin and get sourced instead of the default statler one.. in a sec I'll post a snippet that you can use once you place in ~/bin and chmod +x it.

Last edited by rstrcogburn (2011-04-29 18:11:30)

Well, you gotta live no matter what happens.  -Dallas (John Ford's Stagecoach 1939 Public Domain)

Re: [Solved] Adding a Shutdown option to menu.xml

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    # Hibernate
    def hibernate(self, widget):
        os.system("dbus-send --system --print-reply --dest='org.freedesktop.Hal' /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate && killall python ~/bin/openbox-logout")

    # Suspend
    def suspend(self, widget):
        os.system("dbus-send --system --print-reply --dest='org.freedesktop.Hal' /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0 && killall python ~/bin/openbox-logout")

    # Logout
    def logout(self, widget):
        os.system("openbox --exit")

    # Reboot
    def reboot(self, widget):
        os.system("dbus-send --system --print-reply --dest='org.freedesktop.Hal' /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Reboot && openbox --exit")

    # Shutdown
    def shutdown(self, widget):
        os.system("dbus-send --system --print-reply --dest='org.freedesktop.Hal' /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown && openbox --exit")

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Exit? Choose an option:")
        self.window.set_resizable(False)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(15)

        # Create a box to pack widgets into
        self.box1 = gtk.HBox(False, 0)
        self.window.add(self.box1)

        # Create cancel button
        self.button1 = gtk.Button("_Cancel")
        self.button1.set_border_width(5)
        self.button1.connect("clicked", self.delete_event, "Changed me 
mind :)")
        self.box1.pack_start(self.button1, True, True, 0)
        self.button1.show()

        # Create hibernate button
        self.button2 = gtk.Button("_Hibernate")
        self.button2.set_border_width(5)
        self.button2.connect("clicked", self.hibernate)
        self.box1.pack_start(self.button2, True, True, 0)
        self.button2.show()

        # Create suspend button
        self.button3 = gtk.Button("S_uspend")
        self.button3.set_border_width(5)
        self.button3.connect("clicked", self.suspend)
        self.box1.pack_start(self.button3, True, True, 0)
        self.button3.show()

        # Create logout button
        self.button4 = gtk.Button("_Log out")
        self.button4.set_border_width(5)
        self.button4.connect("clicked", self.logout)
        self.box1.pack_start(self.button4, True, True, 0)
        self.button4.show()

        # Create reboot button
        self.button5 = gtk.Button("_Reboot")
        self.button5.set_border_width(5)
        self.button5.connect("clicked", self.reboot)
        self.box1.pack_start(self.button5, True, True, 0)
        self.button5.show()

        # Create shutdown button
        self.button6 = gtk.Button("_Shutdown")
        self.button6.set_border_width(5)
        self.button6.connect("clicked", self.shutdown)
        self.box1.pack_start(self.button6, True, True, 0)
        self.button6.show()

        self.box1.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    gogogo = DoTheLogOut()
    main()

give that hacked version of openbox-logout a try if you saavy

Well, you gotta live no matter what happens.  -Dallas (John Ford's Stagecoach 1939 Public Domain)

Re: [Solved] Adding a Shutdown option to menu.xml

You could also use ali's logout file, posted here in the Tips n Tricks section

Let's do it and don't screw it.
      Github || Deviantart

Re: [Solved] Adding a Shutdown option to menu.xml

ah yeah.. ali's script is in the same school of thought.. yet more solid than my hack job.. worth checking +100

Well, you gotta live no matter what happens.  -Dallas (John Ford's Stagecoach 1939 Public Domain)

Re: [Solved] Adding a Shutdown option to menu.xml

i tend to use this kind of pygtk logout app on every box.. right now on fvwm.. cleverly named fvwm-logout (yep that's completely unoriginal)

Well, you gotta live no matter what happens.  -Dallas (John Ford's Stagecoach 1939 Public Domain)

Re: [Solved] Adding a Shutdown option to menu.xml

@rstrcogburn I note the calls to dbus to shutdown/reboot/whatever in your script are followed by '&& killall python...' or '&& openbox --exit'. I wonder, by the time dbus has finished its work will there still be anything left to kill or exit?

John
------------------------
( a boring Japan blog , and idle twitterings )
“Good morning sir, which way up would you like your reality today?”  "As it comes, Jeeves, as it comes..."

Re: [Solved] Adding a Shutdown option to menu.xml

@john

I know that this thread has been resolved and what not.  But just for the sharing of experiences sake.  It seems that when returning from a dbus hibernate or suspend that openbox-logout is still running which looks a bit goofy.  The openbox --exit stuff is a controversial one.. I've not found that this addition even matters.  It's always been kept in the script though from iggy koopas work.  Anyways hope my limited knowledge solves your question.

Last edited by rstrcogburn (2011-04-30 05:16:29)

Well, you gotta live no matter what happens.  -Dallas (John Ford's Stagecoach 1939 Public Domain)