On my desktop I use the following menu items for rebooting and halting:
<item label='Shutdown'>
<action name='Execute'>
<command>/usr/local/bin/opBox-exit.sh halt</command>
</action>
</item>
<item label='Reboot'>
<action name='Execute'>
<command>/usr/local/bin/opBox-exit.sh reboot</command>
</action>
</item>
The script /usr/local/bin/opBox-exit.sh
uses zenity
to open a cancel-confirm-dialog and when the confirm button was pressed it executes sudo halt
or sudo reboot
. I configured the sudoers
file so my user wouldn't have to type in a password to run halt
and reboot
with sudo
. For me this is more convenient. Here is the full script
#!/usr/bin/env bash
if [ -z $1 ];then
echo "Usage: $0 [reboot|halt]"
exit
fi
if [ $1 = reboot ];then
zenity --question --ok-label "Reboot" --text "Reboot $HOST?" && sudo /sbin/reboot
elif [ $1 = halt ];then
zenity --question --ok-label "Shudown" --text "Shutdown $HOST?" && sudo /sbin/halt -p
fi
When you want a dialog for the users password I would recommend that you use gksudo halt -p
instead of the whole zenity --question ... && sudo halt -p
stuff. For this your user would still need to be able to execute commands via sudo
. Take a look at man sudoers
for more information.
gksudo
is in the Debain package gksu
.