OB Menu Generator
Goal: Explaining how to log out from openbox using menu.
Table of Content
-
OB Menu Generator: Table of Content
-
1: Basic
1: Basic
Sub menu systemd
Using systemd exit is as easy as:
$ systemctl suspend
$ systemctl hibernate
$ systemctl reboot
$ systemctl poweroff
And the respective openbox menu would be menu.systemd.xml
.
<openbox_pipe_menu>
<item label="Logout">
<action name="Exit" />
</item>
<item label="Suspend">
<action name="Execute"><execute>systemctl suspend</execute></action>
</item>
<item label="Hibernate">
<action name="Execute"><execute>systemctl hibernate</execute></action>
</item>
<item label="Reboot">
<action name="Execute"><execute>systemctl reboot</execute></action>
</item>
<item label="Shutdown">
<action name="Execute"><execute>systemctl poweroff</execute></action>
</item>
</openbox_pipe_menu>
I have test this in my Fedora, openSUSE and Debian.
Sub menu other than systemd
This could be like this in other system (such as openrc). But may vary depend on your setup.
$ pm-suspend
$ pm-hibernate
$ reboot
$ poweroff
It needs workaround to setup this in openbox menu.
Main Menu
And in mainmenu add this.
<?xml version="1.0" encoding="utf-8"?>
<openbox_menu xmlns="http://openbox.org/3.4/menu">
<menu id="system-menu" label="System">
...
</menu>
<menu id="root-menu" label="Openbox 3">
...
<menu id="system-menu"/>
<separator/>
<menu execute="cat /home/epsi/.config/openbox/menu.systemd.xml"
id="exit-menu" label="Exit" >
</menu>
</openbox_menu>
The result is as simply as this one.
2: Forcing Password
The issue with systemctl is, any user can shutdown.
There are some workaround,
such as using gksu
or sudo
.
Just edit your xml menu config.
Using gksu
$ gksu systemctl poweroff
Now your menu could be
<openbox_pipe_menu>
<item label="Logout">
<action name="Exit" />
</item>
<item label="Suspend">
<action name="Execute"><execute>gksu systemctl suspend</execute></action>
</item>
<item label="Hibernate">
<action name="Execute"><execute>gksu systemctl hibernate</execute></action>
</item>
<item label="Reboot">
<action name="Execute"><execute>gksu systemctl reboot</execute></action>
</item>
<item label="Shutdown">
<action name="Execute"><execute>gksu systemctl poweroff</execute></action>
</item>
</openbox_pipe_menu>
Using urxvt sudo
$ urxvt -e sh -c 'sudo systemctl poweroff'
Using xterm sudo
$ xterm -e 'sudo systemctl poweroff'
Setting up sudoers
In order this sudo
to work you,
first you must setup /etc/sudoers
.
root ALL=(ALL) ALL
epsi ALL=(ALL) ALL
Or setup wheel
group.
%wheel ALL=(ALL) ALL
Or in openSUSE, there is something like this:
Defaults targetpw
ALL ALL=(ALL) ALL
3: Forcing No Password
Now consider to see non-systemd again.
$ pm-suspend
$ pm-hibernate
$ reboot
$ poweroff
The respective openbox menu would be menu.openrc.xml
.
<openbox_pipe_menu>
<item label="Logout">
<action name="Exit" />
</item>
<item label="Suspend">
<action name="Execute"><execute>xterm -e sudo pm-suspend</execute></action>
</item>
<item label="Hibernate">
<action name="Execute"><execute>xterm -e sudo pm-hibernate</execute></action>
</item>
<item label="Reboot">
<action name="Execute"><execute>xterm -e sudo reboot</execute></action>
</item>
<item label="Shutdown">
<action name="Execute"><execute>xterm -e sudo poweroff</execute></action>
</item>
</openbox_pipe_menu>
And set in /etc/sudoers
,
to make it behaves like systemctl.
Use no password.
%wheel ALL=(ALL) NOPASSWD: ALL
I have test this in my Gentoo.
4: Custom Dialog
There is, however, this old good trick from urukrama, using gxmessage. gxmessage is not very common, and not available in all distro.
Let me rewrite the good script for a modern days systemd style.
#!/bin/bash
gxmessage "Are you sure you want to shut down your computer?" \
-center -title "Take action" \
-font "Sans bold 10" \
-default "Cancel" \
-buttons "_Cancel":1,"_Log out":2,"_Reboot":3,"_Shut down":4 \
>/dev/null
case $? in
1) echo "Exit";;
2) openbox --exit;;
3) systemctl reboot;;
4) systemctl poweroff;;
esac
Or the ugly one.
What’s Next
We are almost finished with openbox configuration.
Consider continue reading [ Openbox: Exit ].