Linux Uprising blog

How To Add A Show Desktop Icon To Ubuntu Dock / Dash To Dock

If you're a Gnome Shell user and you're missing having a Show Desktop icon on your dock to quickly show / hide all open windows, here's a script to achieve this with the Ubuntu Dock, Dash to Dock, or any dock you may be using.Dash to Panel users don't need to use a script. The Dash To Panel Gnome Shell extension has an option to enable a Windows-like Show Desktop button at the right-hand side end of the dock. This can be done from the Dash to Panel Settings > Behavior > Show Desktop button.

For docks like the Ubuntu Dock, Dash To Dock or others, here's a script that you can use to get a Show Desktop button on your Gnome Shell dock.

This article includes 2 scripts from which you'll have to choose one. The first script, which we'll call Script A, hides and shows visible windows only, so if some windows were minimized, they won't be restored when using the Show Desktop icon. Script B restores all windows, including those that were previously minimized, so even if some windows were previously minimized and they weren't hidden by clicking on the Show Desktop icon, they are restored when clicking the Show Desktop icon for the second time, along with the other windows.

Let's get started.

1. Install wmctrl

We'll use wmctrl to show and hide open windows, so you need to install this tool. In Debian / Ubuntu you can install it using this command:

sudo apt install wmctrl

2. Create the script and make it executable

Run the following commands to create a file called show-desktop in /usr/local/bin and open this file as root, with a text editor (Gedit):

After you type the root password, the /usr/local/bin/show-desktop file should open in Gedit. In this file, paste the contents of one of the two following scripts (only use one - choose the one that suits your needs):

Script A (restores only windows that were previously visible, ignores previously minimized windows):

4. Now search for Show Desktop among your applications (Activities / Applications button), right click the Show Desktop icon and select Add to Favorites.

After this, the Show Desktop icon should show up on your Dash to Dock / Ubuntu Dock. For other docks, you may need to drag and drop the Show Desktop icon from ~/.local/share/applications/ onto the dock to pin it.

You can now try your new Gnome Shell Show Desktop icon from your dock.

Another way to show the desktop in 18.04 is to move the mouse cursor to the upper left corner of the screen and when the window display screen opens go to the right of the screen and double click the bottom window thumbnail to open a blank desktop. When you want to return to your original desktop you can click any icon in list on the left that is open (marked with a red dot). This might sound complex, but it's actually easy and intuitive.