How to add Show Desktop Icon to Ubuntu Dock

0

Having upgraded from Ubuntu 16.04 to Ubuntu 18.04 the first thing I noticed was that there was no show desktop icon on the Ubuntu Dock. I couldn’t find a way to turn this back on in the settings so instead I used a script provided by “AndAC” in this AskUbuntu post.

The following guide will explain how to add a show desktop icon to your Ubuntu Dock and quickly hide/show your active windows.

Install wmctrl

In order to hide the active windows you need to install wmctrl using :

sudo apt install wmctrl

Create show-desktop Script

Now create a file to contain the script that will do the work. Here we use the nano text editor but you can use another text editor if you prefer :

sudo nano /usr/local/bin/show-desktop

Enter your admin password if prompted to.

When the text editor opens paste in the following script :

#!/bin/bash
status="$(wmctrl -m | grep "showing the desktop" | sed -r 's/(.*)(ON|OFF)/\2/g')"

if [ $status == "ON" ]; then
wmctrl -k off
else
wmctrl -k on
fi

This script will hide the active windows and restore them when run again. Windows that were previously minimised will be ignored.

Change Permissions

Now make the script file executable by changing the permissions :

sudo chmod +x /usr/local/bin/show-desktop

Create a Show Desktop desktop file

The last file to create is a desktop icon file :

nano ~/.local/share/applications/show-desktop.desktop

When the editor loads paste in the following details :

[Desktop Entry]
Type=Application
Name=Show Desktop
Icon=desktop
Exec=show-desktop

This defines an icon and specifies the script that will be run when it is clicked.

Add Show Desktop Icon To Ubuntu Dock/Launcher

Finally click your “Show Applications” button and type “show desk” into the search box. You should see the desktop icon as shown below.

Right click on the icon and select “Add to Favourites”.

Ubuntu Show Desktop Icon

The icon should be added to your dock. Re-positioned it as required.

Clicking the Show Desktop icon should hide all active windows. Clicking it again should restore those windows.

Share.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.