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 folder to contain the script that will do the work.
mkdir ~/.local/bin
Then we use the nano text editor to create the script. You can use another text editor if you prefer :
sudo nano ~/.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 ~/.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=/home/USERNAME/.local/bin/show-desktop
This defines an icon and specifies the script that will be run when it is clicked.
NOTE: You MUST replace USERNAME in the script above with YOUR username.
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”.
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.