Last active
November 8, 2020 09:12
-
-
Save redbug312/70a87e2f966b21f54f7de3ecf5e8c6d7 to your computer and use it in GitHub Desktop.
Bash script to lift and focus on (most recently focused) apps.
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 | |
# https://askubuntu.com/a/562191 | |
usage() { | |
echo Usage: $(basename $0) PATTERN | |
exit 1 | |
} | |
[ $# -ne 1 ] && usage | |
pattern=$1 | |
workspace=$(wmctrl -d | grep '\*' | cut -d' ' -f1) | |
targets=$(wmctrl -lx | grep -i $pattern | grep " $workspace " | cut -c-10 | sed -ne 's|0x0\+|0x|gp') | |
if [ -z "$targets" ]; then | |
echo No such window in workspace | |
exit 1 | |
fi | |
recents=$(xprop -root _NET_CLIENT_LIST_STACKING | sed -ne 's|.\+#|,|' -e 's|, | |gp' | tac -s ' ') | |
for candidate in $recents; do | |
if echo $targets | grep -q $candidate; then | |
# wmctrl -lx | grep $candidate # debug | |
wmctrl -ia $candidate | |
exit 0 | |
fi | |
done | |
echo Accidental error | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment