Ubuntu – How to add “Show desktop” to the GNOME dash or Ubuntu Dock

gnomegnome-shellgnome-shell-extensionshow-desktopubuntu-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.)

Best Answer

I found a way to do that:

  1. Open a terminal and install wmctrl:

    sudo apt-get install wmctrl
    
  2. 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
    
  3. 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
    
  4. Open the dash, search for show desktop and add it to the favorites.