How can I add "Show desktop" to the GNOME dash or Ubuntu Dock?
I am migrating from Unity to GNOME. One item I am missing is a "Show desktop" button (aka "minimise all windows") in the dash. How can I add this functionality to the GNOME dash (or Ubuntu dock in Ubuntu 17.10 and later), even if it means making a custom .desktop
file?
(I know that I can use the Ctrl + Super + D keyboard shortcut to show the desktop and that I can install an extension to add a "Show desktop" button to the top bar, but I specifically want a button in the dash.)
I found a way to do that:
-
Open a terminal and install
wmctrl
:sudo apt-get install wmctrl
-
Create a shell script named
show-desktop.sh
(I put it in my home folder)gedit ~/show-desktop.sh
place this code in there:
#!/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
and make it executable:
chmod +x ~/show-desktop.sh
-
Create a file
show-desktop.desktop
in~/.local/share/applications/
folder:gedit ~/.local/share/applications/show-desktop.desktop
Add this text and save (don't forget change the value on
<your user>
):[Desktop Entry] Type=Application Name=Show Desktop Icon=user-desktop Exec=/home/<your user>/show-desktop.sh
Open the dash, search for show desktop and add it to the favorites.
First off, know that keyboard shortcuts Super (Windows Key) + D, or Ctrl + Alt + D will toggle between showing/hiding the desktop. You may get used to this keyboard shortcut and decide it's better than clicking an icon anyway. Nevertheless, we can create a clickable shortcut which will simply do this keyboard shortcut for us to show/hide the desktop.
Note that I recommend using Option 1 [MY PREFERRED CHOICE] OR one of the methods from Option 2 below, but not both Option 1 and Option 2 together, as they seem to conflict in weird ways. Ie: if you set up Option 1 then set up one of the Option 2's, just remove the Show Desktop icon from Option 1 as a favorite, and stop using it. Weird things happen if you click the Show Desktop icon from Option 1 after installing one of the Option 2s. I think this is because xdotool
(used by Option 1) is attempting to send messages to your system as though they came from your keyboard, so however the Option 2 methods work, they conflict with xdotool
or something and sometimes your Super key or mouse keys seem to get "stuck" down simply by using both Options together. Note that this unusual and buggy behavior does NOT present itself, however, if you manually use the Super + D shorcut together with an Option 2 method, OR if you use just the Option 1 method and no Option 2 methods.
My recommendation is to use the Option 1 method below in conjunction with the Super (Windows Key) + D keyboard shortcut whenever you feel like using the keyboard shortcut instead.
This suits me the best.
Option 1 (MY PERSONAL FAVORITE):
Tested and works in Ubuntu 14.04, 16.04, 18.04, 20.04.
Credit: I didn't come up with this, Ubuntu genius & blogger Ji m did, here: http://ubuntuhandbook.org/index.php/2018/10/add-show-desktop-button-ubuntu-18-10-18-04/. I'm borrowing directly from his material (a lot of it quoted directly):
-
"Open terminal (Ctrl + Alt + T) and install xdotool:"
sudo apt install xdotool
-
"Then create the show desktop shortcut icon and edit it via command:"
gedit ~/.local/share/applications/show-desktop.desktop
"When the file opens, paste following lines and save it."
[Desktop Entry]
Type=Application
Name=Show Desktop
Icon=desktop
Exec=xdotool key --clearmodifiers Super+d
- "Finally search for ‘show desktop’ in application menu, then right lick and select ‘add to favorites’:"
"That’s it. Enjoy!"
Here it is, as shown on my desktop:
Option 2:
Option 2.A:
Click your "Start menu" icon thing (9-dot icon) and type in "show desktop." Wait a few seconds for search results to pop up, and click on and install one of the Gnome Shell extensions. (Note that these search results are simply coming from the Ubuntu Software center).
For more info on Gnome Shell Extensions, see my other answer here: https://askubuntu.com/a/1089033/327339.
Ex: here's the first one:
Click the "Install" button and here's what it looks like on my desktop:
Option 2.B:
Here's another one [used to be my personal favorite, but then I switched back to Option 1 because it seems to work the smoothest and be the most consistent]:
And here's what it looks like installed: