I have been using the latest Openbox release [3.4.7-pre2] for the last few weeks and so far I have been impressed. One of the new features from the latest release is a GDM control script. The script basically allows for a user to send reboot and shutdown signals to GDM from within the Openbox environment. This provides a means to reboot/shutdown an Openbox system in a clean and efficient manner.
I have written the following PyGTK script to take advantage of the new GDM control. Python is not currently a language that I am too familiar with, so please feel free to rip the script to bits improve as you see fit.
#!/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
# Logout
def logout(self, widget):
os.system("openbox --exit")
# Reboot
def reboot(self, widget):
os.system("gdm-control --reboot && openbox --exit")
# Shutdown
def shutdown(self, widget):
os.system("gdm-control --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(20)
# 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(10)
self.button1.connect("clicked", self.delete_event, "Changed me mind :)")
self.box1.pack_start(self.button1, True, True, 0)
self.button1.show()
# Create logout button
self.button2 = gtk.Button("Log out")
self.button2.set_border_width(10)
self.button2.connect("clicked", self.logout)
self.box1.pack_start(self.button2, True, True, 0)
self.button2.show()
# Create reboot button
self.button3 = gtk.Button("Reboot")
self.button3.set_border_width(10)
self.button3.connect("clicked", self.reboot)
self.box1.pack_start(self.button3, True, True, 0)
self.button3.show()
# Create shutdown button
self.button4 = gtk.Button("Shutdown")
self.button4.set_border_width(10)
self.button4.connect("clicked", self.shutdown)
self.box1.pack_start(self.button4, True, True, 0)
self.button4.show()
self.box1.show()
self.window.show()
def main():
gtk.main()
if __name__ == "__main__":
gogogo = DoTheLogOut()
main()
9 Responses to “Openbox Logout, Reboot & Shutdown Script”
-
uterrorista wrote,
Hi! Looks god to me. But, how do i run the script?? :D
-
Philip wrote,
Hi uterrorista
To create/run the script, copy it into a new file say,/usr/bin/openbox-logout
and make the file executable. You can then call the script from your Openbox menu or via the terminal withopenbox-logout
— or whatever you named the file.I should also have mentioned that the GDM features are available in Openbox 3.4.7-pre2.
I personally choose for a keybinding in the rc.xml file:
2 comments:
If you don't have gdm installed, you can change those commands to "sudo shutdown -r now && openbox --exit " for reboot, and "sudo shutdown -h now && openbox --exit" for halt/shutdown.
Make sure you have shutdown so you don't need password for sudo. (There are instructions in various places for this.)
Uh? What's the point of having "&& openbox --exit" AFTER "shutdown"? As far as I know, or as I thought I knew, it makes as much sense as "sudo shutdown -h now && have a nice dream while you're off the power, dear computer".
Doesn't "&&" means to do something after the preceding command is finished/exits? That's what it does in the rest of the time (e.g.: "sleep 3s && echo "slept 3s"). Does this get any different when "shutdown" is the preceding command for some reason?
Post a Comment