Last active
October 26, 2021 09:47
-
-
Save mesuutt/62b0091fadf8927d436d5694c899984a to your computer and use it in GitHub Desktop.
Check active window every second and run script when window class changed
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
# .... | |
# Run script if not running. | |
if ! pidof -x "catch_window_change.sh" > /dev/null; then | |
(~/bin/catch_window_change.sh > /dev/null 2>&1 &) | |
fi |
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
#!/bin/bash | |
LAST_WIN='' | |
while true; do | |
WIN_CLASS=$(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_CLASS | cut -d "," -f2 | sed 's/\"//g') | |
if [ -z $LAST_WIN ]; then | |
LAST_WIN=$WIN_CLASS | |
fi | |
if [ "$WIN_CLASS" != "$LAST_WIN" ]; then | |
# Window changed | |
echo 'Window changed' | |
LAST_WIN=$WIN_CLASS | |
fi | |
sleep 1; | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment