Skip to content

Instantly share code, notes, and snippets.

@milovangudelj
Last active March 30, 2022 01:01
Show Gist options
  • Save milovangudelj/ed5003c6c55b4c42a70f397b28eb756d to your computer and use it in GitHub Desktop.
Save milovangudelj/ed5003c6c55b4c42a70f397b28eb756d to your computer and use it in GitHub Desktop.
A script to show/hide any window given it's name
#!/bin/bash
version=1.0.0
name=$1
mode=windowunmap
# Print help message
function help()
{
echo "Tray - v$version"
echo
echo "Usage: tray [name] [options]"
echo
echo "Options"
echo -e " -s, --show\tShow window if it's hidden and existing."
echo -e " -h, --help\tPrint help message."
exit 0
}
# Print unrecognised option message
function unrecognised()
{
echo "tray: Unrecognised argument provided..."
echo "Try 'tray --help' for more information."
exit 1
}
# Parse command arguments
options=$(getopt -o 'sh' --long 'show,help' -n "tray" -a -q -- "$@") # -q suppresses default error messages
if [ $? -ne 0 ]; then
unrecognised
fi
# Note the quotes around "$options": they are essential!
eval set -- "$options"
while true;
do
case "$1" in
'-s'|'--show')
mode=windowmap
break
;;
'-h'|'--help')
help
;;
"--")
shift
break
;;
?)
echo 'Internal error!' >&2
exit 1
;;
esac
done
win_id=$(xdotool search --name "$name")
xdotool $mode $win_id
@milovangudelj
Copy link
Author

This script uses xdotool to show/hide any window given it's name as the first parameter.

Installation

  1. Place the script file in /usr/local/bin
  2. Make it executable with sudo chmod 755 /usr/local/bin/tray
  3. Enjoy

Usage

tray [name] [options]

Options

-s, --show: Show window if it's hidden and existing.
-h, --help: Print help message.

If only the name is provided, it will hide the window by default.

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