If you are a Gnome Shell user and you don’t have a “show desktop” icon on the dock to quickly show/hide all open windows, you can use the following script to achieve use.Dash to the panel Users do not need to use scripts. The Dash To Panel Gnome Shell extension has an option to enable the Show Desktop button similar to Windows at the right end of the dock. This can be
Dash to Panel Settings > Behavior > Show Desktop buttonFor docks such as Ubuntu Dock, Dash to the pier Or other scripts, you can use this script to get the “Show Desktop” button on the Gnome Shell base. This article includes 2 scripts, you must choose one of them. The first script (we call it script A) only hides and shows visible windows, so if you minimize some windows, you will not be able to restore them 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 not hidden by clicking the “Show Desktop” icon, they will be clicked a second time. Restore it when the desktop icon is displayed. With other windows.
Let’s get started 1. Install
We will use
wmctrl Show and hide open windows, so you need to install this tool. In Debian/Ubuntu, you can use the following command to install:
sudo apt install wmctrl
2. Create a script and make it executable
Run the following command to create a file called
/usr/local/bin And use a text editor (Gedit) to open this file as root:
sudo touch /usr/local/bin/show-desktop gedit admin:///usr/local/bin/show-desktop
After typing the root password,
/usr/local/bin/show-desktop The file should be opened in Gedit. In this file, paste the content of one of the following two scripts (use only one-choose the one that suits your needs):
- Script A (only restore previously visible windows, ignoring previously minimized windows):
#!/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
- Script B (restore all windows, including minimized windows):
#!/bin/sh #Record Open Windows and Minimize Them open_windows=$(wmctrl -l | cut -f1 -d " ") if wmctrl -m | grep -e "mode: OFF" -e "mode: N/A" ; then wmctrl -k on fi #Restore Minimized Windows (in the order in which they were opened - newest on top)* if wmctrl -m | grep "mode: ON" ; then for i in $open_windows do wmctrl -i -R "$i" done fi
Use the following command to save the file and make it executable:
sudo chmod +x /usr/local/bin/show-desktop
3. Create Show Desktop file in it
To make the script appear on the dock/panel, we will create a desktop file for it. Create a file called
~/.local/share/applications/ And use Gedit to open it, use:
Paste the following content in this file:
[Desktop Entry] Type=Application Name=Show Desktop Icon=desktop Exec=show-desktop
And save the file 4. Search now
Show Desktop In your application (activity/application button), right click
Show Desktop Icon and select
Add to Favorites.
After that, the “Show Desktop” icon should be displayed on Dash to Dock / Ubuntu Dock. For other docks, you may need to change the “Show Desktop” icon from
~/.local/share/applications/ Fixed on the base.
Now you can try the new Gnome Shell Show Desktop icon from the dock.
The icon may not be updated until you log out and log in again.
Script credits: Script A | Script B