Skip to content

Instantly share code, notes, and snippets.

@Not-Dhanraj
Created December 11, 2025 20:40
Show Gist options
  • Select an option

  • Save Not-Dhanraj/b0006aedf07cccda2062be1aa0036423 to your computer and use it in GitHub Desktop.

Select an option

Save Not-Dhanraj/b0006aedf07cccda2062be1aa0036423 to your computer and use it in GitHub Desktop.
A simple bash script to enable Windows-like toggle show desktop behavior in GNOME using wmctrl

GNOME Toggle Show Desktop Script

A simple script to enable Windows-like "toggle show desktop" behavior in GNOME.

Prerequisites

Install wmctrl:

# Debian/Ubuntu
sudo apt install wmctrl

# Fedora
sudo dnf install wmctrl

# Arch
sudo pacman -S wmctrl

Installation

  1. Create the script directory and file:
mkdir -p ~/.local/bin
nano ~/.local/bin/toggle-desktop.sh
  1. Copy the script content:
#!/bin/bash
if [ -f /tmp/desktop-shown ]; then
    wmctrl -k off
    rm /tmp/desktop-shown
else
    wmctrl -k on
    touch /tmp/desktop-shown
fi
  1. Make it executable:
chmod +x ~/.local/bin/toggle-desktop.sh

Setting Up the Keyboard Shortcut

  1. Open SettingsKeyboard
  2. Scroll down and click "View and Customize Shortcuts""Custom Shortcuts"
  3. Click the "+" button
  4. Configure:
    • Name: Toggle Show Desktop
    • Command: /home/yourusername/.local/bin/toggle-desktop.sh (replace yourusername with your actual username)
    • Shortcut: Press Super + D (or your preferred combination)

Usage

Press Super + D (or what you chose) to minimize all windows and show desktop. Press it again to restore all windows.

How It Works

The script uses wmctrl to show/hide the desktop and maintains state using a temporary flag file (/tmp/desktop-shown) to track whether windows are currently minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment