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
  • 7,426
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
  • 418