1

How can I shutdown my laptop in one mouse click (or maybe two mouse clicks) from the unity launcher?

I've found a number of posts which describe how to create a unity launcher so you can shutdown your laptop with one mouse click - but these are for older versions of Unbuntu (16.04 etc). https://www.faqforge.com/linux/distributions/ubuntu/trigger-system-shutdown-ubuntu-unity-launcher/

Unfortunately these methods don't appear to work with the current version of Unity. Any help would be much appreciated.

Ian
  • 13

2 Answers2

1

In case you are using a standard Ubuntu with "gnome" (not unity - which would make not much difference) here my proposal: create a file like /home/yourusername/.local/share/applications/exit.desktop

Add the following code:

#!/usr/bin/env xdg-open
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Exec=systemctl poweroff
Name=My Exit
Comment=One Click Exit 
Icon=application-exit
NoDisplay=false
Categories=Utilities;System

Save it. I had to change the "group" to "adm", by using the properties dialog:

Go to activities and search for "exit". Rightclick the icon and add it as "favorite". Now you have your icon (choose any you like) in the "dock"...

kanehekili
  • 6,402
  • Thank you. This works brilliantly and is exactly what I was trying to do. – Ian Dec 15 '21 at 16:59
  • Then you should accept the answer. It honors the time one put into it ;-) – kanehekili Dec 15 '21 at 23:11
  • :-) Accepted the answer - Thanks.......BTW it's not that obvious to a new user that you are supposed to do this?? – Ian Dec 17 '21 at 12:18
  • No sir. There might be tools around (I haven't checked) but it took me some time in the past to figure it out Glad I could share and it helped you. Especially Gnome incapacitates the user - one of the reasons why I'd prefer either KDE or XFCE. But it is a good place to start, as long as Gnome will provide a terminal ;-) – kanehekili Dec 17 '21 at 22:58
  • For me I had a system that was having graphics problems. Monitors going blank - so the top panel could not be seen or accessed. So (a) use gnome-extension to put the launcher (at least for now) on all monitors (ran gnome-extensions prefs dash-to-dock@micxgx.gmail.com) and (b) create the button per kanehekili answer and add to the dash/launcher. Now I have a quick shutdown button on all screens/monitors - much better than yanking power every time the graphics go wonky. Thanks kanehekili!!! – Art Swri May 16 '23 at 16:53
0

This is a very good question because shutting down Ubuntu 22.04 is a multi step process that I find very annoying.

Here is my solution for shutting down Ubuntu 22.04 running Gnome desktop in one mouse click. You can also use this method to create launchers for any bash script you would like to launch from your Dash, Activities or Desktop.

  1. mkdir /home/$USER/shutdown (creates a folder called shutdown in home)
  2. nano /home/$USER/shutdown/shutdown.sh (creates a bash script in /shutdown)

Add the following to shutdown.sh

#! /bin/bash
shutdown now

and save shutdown.sh (in nano ctrl-o, enter, ctrl-x)

#! /bin/bash identifies the file as a bash script. shutdown now is the bash command to shut down and "now" means now, not later.

  1. chmod 775 /home/$USER/shutdown/shutdown.sh (sets shutdown.sh permission to -rwxrwxr-x)

  2. nano /home/$USER/.local/share/applications/shutdown.desktop (creates a .desktop file in /applications)

Add the following to shutdown.desktop

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/home/$USER/shutdown/shutdown.sh
StartupNotify=false
Name=Shutdown
Icon=/home/$USER/shutdown/shutdown.png

and save shutdown.desktop (in nano ctrl-o, enter, ctrl-x). Exec= sets the path to the bash script containing the command to shutdown. Name= sets the name of the command as found in Activities. Icon= sets the path to the icon.

  1. chmod 775 /home/$USER/shutdown/shutdown.desktop (sets shutdown.desktop permission to -rwxrwxr-x)

  2. Save a suitable shutdown icon to /home/$USER/shutdown such as the following:

enter image description here

be sure to name the icon file identical to that given in Icon= statement in the .desktop file. In this example the icon file is shutdown.png.

  1. There are three ways you may now launch shutdown.sh

    a. Press the Super key, type shutdown and then select the shutdown icon.

    b. Press the Super key, type shutdown, right click the shutdown icon and select "Add to Favorites" to place the shutdown icon on the dash.

    c. Copy the shutdown.desktop file to your desktop, right click and select "Allow Launching".

This is a rather lengthy explanation but it serves to demonstrate how to properly link a bash script to a graphical launcher. A bash script can perform many useful task such as executing system commands, mounting drives, performing backups or launching applications. The sky is the limit.

brett
  • 410
  • 1
  • 4
  • 14