Of course! Here is a bash script that accomplishes this on Fedora with GNOME on Wayland.
This script uses a clever trick. Since Wayland's security model prevents applications from directly controlling the cursor's visibility (unlike the older X11 system), we can't use traditional tools like unclutter or xdotool.
Instead, this script works by:
- Getting your current cursor theme name.
- Setting the cursor theme to a non-existent name, which causes GNOME to render it as invisible.
- Waiting for 5 seconds.
- Restoring your original cursor theme, making it visible again.
It also includes a trap to ensure your cursor is restored even if you interrupt the script (e.g., with Ctrl+C).
The Script: hide-cursor.sh
#!/bin/bash
# A script to temporarily hide the mouse cursor on GNOME (Wayland/X11).
#
# This works by getting the current cursor theme, setting it to a non-existent
# theme (which makes it invisible), waiting, and then restoring the original theme.
#
# It includes a trap to ensure the cursor is restored if the script is interrupted.
# --- Configuration ---
HIDE_DURATION=5 # Seconds to hide the cursor
# --- Script Logic ---
# Check if gsettings is available
if ! command -v gsettings &> /dev/null; then
echo "Error: 'gsettings' command not found. This script requires a GNOME-based desktop."
exit 1
fi
# Get the current cursor theme and remove the single quotes gsettings adds
ORIGINAL_THEME=$(gsettings get org.gnome.desktop.interface cursor-theme | tr -d "'")
# Define a cleanup function to restore the cursor
function restore_cursor {
echo -e "\nRestoring cursor theme to '$ORIGINAL_THEME'..."
gsettings set org.gnome.desktop.interface cursor-theme "$ORIGINAL_THEME"
echo "Done."
}
# Set a trap to call the cleanup function on script interruption (Ctrl+C) or termination
trap restore_cursor SIGINT SIGTERM
echo "Hiding cursor for $HIDE_DURATION seconds..."
# Hide the cursor by setting a blank/non-existent theme name
# The double quotes with an empty string '' are intentional.
gsettings set org.gnome.desktop.interface cursor-theme "''"
# Wait for the specified duration
sleep $HIDE_DURATION
# Restore the cursor normally
restore_cursor
# Disable the trap so the cleanup function doesn't run twice on normal exit
trap - SIGINT SIGTERM
exit 0
How to Use the Script
-
Save the Code: Open a text editor, paste the code above, and save the file with a name like hide-cursor.sh.
-
Make it Executable: Open a terminal, navigate to the directory where you saved the file, and run the following command to give it execute permissions:
chmod +x hide-cursor.sh
-
Run the Script: Execute the script from your terminal:
./hide-cursor.sh
You will see the following output, and your mouse cursor will disappear for 5 seconds before reappearing.
Hiding cursor for 5 seconds...
Restoring cursor theme to 'Adwaita'...
Done.