Quantcast
Results 1 to 1 of 1

Create a desktop launcher (shortcut) to shutdown\restart Ubuntu.

  1. #1
    fjgold's Avatar
    fjgold is offline Senior Member
    Enjoys Windows 7 Forums
     
    Join Date
    Jan 2009
    Age
    62
    Posts
    556

    Create a desktop launcher (shortcut) to shutdown\restart Ubuntu.

    Hi Folks, Cybermoron posted a thread on creating a nifty shutdown button on the Win 7
    desktop to make shutdown\restart easier.
    I posted that I use a similar method to shutdown\restart my Ubuntu installs using a simple
    python script.

    He suggested I share that here in the Linux section so here goes.

    First I can't take credit for the script it was created by another individual over at the Ubuntu forums.

    Below is the script text.

    Code:
    #!/usr/bin/env python
    
    import os
    import sys
    import pygtk
    import gtk
    
    class power:
        
        def restart(self, event):
                command = "sudo shutdown -r now"
                os.system(command)
            
        def shutdown(self, event):
            command = "sudo shutdown -h now"
            os.system(command)
            
        def cancel(self, event):
            import sys
            sys.exit()
            
        def delete_event(self, widget, event, data=None):
                gtk.main_quit()
                return False
        
        def __init__(self):
            self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            self.window.set_title("Power Options")
            self.window.connect("delete_event", self.delete_event)
            self.window.set_border_width(10)
            
            self.box1 = gtk.HBox(False, 0)
                self.window.add(self.box1)
        
            self.button1 = gtk.Button("Restart")
            self.button1.connect("clicked", self.restart)
            self.box1.pack_start(self.button1, True, True, 0)
            
            self.button2 = gtk.Button("Shutdown")
            self.button2.connect("clicked", self.shutdown)
            self.box1.pack_start(self.button2, True, True, 0)
            
            self.button3 = gtk.Button("Cancel")
            self.button3.connect("clicked", self.cancel)
            self.box1.pack_start(self.button3, True, True, 0)
            
                    self.window.set_position(gtk.WIN_POS_CENTER)
            self.button1.show()
            self.button2.show()
            self.button3.show()
            self.box1.show()
            self.window.show()
    def main():
        gtk.main()
        
    if __name__=="__main__":
        pwr = power()
        main()
    The first thing to do is to right click an empty area of your desktop and choose "create document>empty file".
    Open the resulting empty file in gedit or another suitable text editor and copy\paste all the text from the script above into the empty document file.
    Save and name the file power_options.

    Next right click the newly created power_options file and select properties>permissions and make sure that "allow executing file as a program" is selected.
    All other permissions should be correct if you created the file on your desktop.

    Close the properties dialog box and move the file to your /home/<your user name> folder
    where <your user name> is your user name without the <> symbols.

    The two commands below should be done in terminal as user.
    Do not do as root.

    You can do this from the terminal by typing
    Code:
    cd Desktop
    and clicking enter.
    The D in desktop must be uppercase.

    then

    Code:
    cp power_options /home/<your user name>
    again your own user name without the <> symbols and click enter.



    Alternatively if you have a desktop shortcut to your /home directory just cut and copy the file to it.

    Now that the file is in your /home directory we will now make a desktop launcher (shortcut) to it.

    Right click a blank area of your desktop and choose "Create Launcher..".
    In the resulting dialog box make sure "application" is selected in the type: dropdown menu.
    In the name: field name then launcher anything you want, I chose Quit.
    In the command: field type python /home/<your user name>/power_options, again using your actual user name without <> where it says <your user name>.

    In the upper left corner of the launcher dialog box is a generic icon.
    Click this icon to change the icon to a more acceptable one from the list.
    If you have an icon of your own then place it in your /home directory and navigate to it using the browse feature.

    attached below is the icon I use.

    Click image for larger version. 

Name:	exit.png 
Views:	2745 
Size:	11.0 KB 
ID:	6323

    If you want to use this icon just click on the attachment thumbnail and right click the resulting image and choose "save image as..." and save it to your /home folder.
    It will be saved as a .png.
    Navigate to that icon file as instructed above to use it as your icon.

    Click ok when done and you should have a brand new launcher on your desktop with
    the icon of your choice.

    Right click the new launcher and choose properties>permissions and make sure "allow executing file as a program" is selected, close the properties box and you launcher is ready for use.

    When clicked your new shutdown button will open a small dialog box where you can select shutdown, restart or cancel.

    I've tested this on all versions of Ubuntu from Dapper Drake (Ubuntu 6.04 LTS) to the latest Lucid Lynx (Ubuntu 10.04 LTS) and the launcher works very well.
    I haven't tested it the KDE versions (Kubuntu) but it should work just as well.

    It should work on other debian based Linux distros but I haven't tested it.

    Have fun with your new Desktop shutdown button.
    Last edited by fjgold; 05-16-2010 at 03:54 PM.

    Reply With Quote Reply With Quote


Similar Threads

  1. Replies: 0
    Last Post: 02-23-2011, 04:20 PM
  2. Replies: 0
    Last Post: 10-03-2010, 09:10 AM
  3. How create shortcut to Windows Explorer?
    By alant in forum Windows 7 Support
    Replies: 3
    Last Post: 08-10-2010, 06:52 AM
  4. Create a Universal Shortcut for Composing an Email
    By loathe in forum Tweaks, Guides, and HOWTO
    Replies: 0
    Last Post: 06-18-2009, 05:26 PM
  5. Replies: 3
    Last Post: 05-08-2009, 12:07 PM

Visitors found this page by searching for:

how to make a shutdown launcher in ubuntu

ubuntu shutdown shortcut

shutdown in launcher ubuntu

Herunterfahren symbol windows

script to shut down desktop ubuntu

create one click button to shutdown in ubuntu

desktop shutdown ubuntu

ubuntu how to create an icon to shutdown

shutdown launcher ubuntu

ubuntu shutdown desktop

debian shutdown shortcut

what are the properties of a launcher in debian

create shutdown icon ubuntu

shutdown ubuntu launcher

script shutdown ubuntu windows

create shutdown launcher ubuntu

restartshutdown icons

create shutdown launcher

ubuntu desktop shutdown launcher

launcher shutdown ubuntu

ubuntu lanciatore shutdown

ubuntu create shutdown shortcut

ubuntu how to create a shortcut to shutdown

desktop icon shutdown

ubuntu icona spegnimento su scrivania

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •