Skip to content

Instantly share code, notes, and snippets.

@redbug312
Last active November 8, 2020 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redbug312/70a87e2f966b21f54f7de3ecf5e8c6d7 to your computer and use it in GitHub Desktop.
Save redbug312/70a87e2f966b21f54f7de3ecf5e8c6d7 to your computer and use it in GitHub Desktop.
Bash script to lift and focus on (most recently focused) apps.
#!/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