-
-
Save milovangudelj/ed5003c6c55b4c42a70f397b28eb756d to your computer and use it in GitHub Desktop.
A script to show/hide any window given it's name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script uses
xdotool
to show/hide any window given it's name as the first parameter.Installation
/usr/local/bin
sudo chmod 755 /usr/local/bin/tray
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.