Created
February 12, 2017 08:50
-
-
Save ohmree/ea4c1e0bbd16dd562e09081809bc0899 to your computer and use it in GitHub Desktop.
A script for doing actions on windows
This file contains 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
#!/usr/bin/env bash | |
# | |
## window-tools.sh - brings a window to the front | |
# | |
# Some bash stuff for safety, should work since the shebang uses bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
# Usage string | |
_USAGE=" | |
usage: $0 [OPTION]... | |
Actions: | |
front <WIN> Bring a window to the front | |
open <APPLICATION> Tell if an application is open or not | |
list List all open windows | |
" | |
# List of currently open windows, awk magic that I don't fully understand | |
_WINS=$(wmctrl -l | awk '{$3=""; $2=""; $1=""; print $0}') | |
# List of IDs of currently open windows, unused | |
#_WINID=$(wmctrl -l | awk '{$3=""; $2=""; print $1}') | |
# If no arguments are received | |
if [ $# -lt 1 ] | |
then | |
printf "%s" "$_USAGE" # Print usage string | |
else | |
if [ "$1" = "front" ] # If first argument is "front" | |
then | |
wmctrl -a "$2" # Use wmctrl to jump to the window | |
elif [ "$1" = "list" ] # If first argument is "list" | |
then | |
printf "%s\n" "$_WINS" # Print list of currently open windows | |
elif [ "$1" = "open" ] # If first argument is "open" | |
then | |
for _app in $_WINS # Iterate over currently open windows | |
do | |
# This part is not POSIX compliant, sorry | |
if [[ "$_app" =~ $2 ]] # If app $2 is in the list of apps | |
then | |
printf "%s is open!\n" "$2" # Inform the user that application $2 is open | |
fi | |
done | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment