Skip to content

Instantly share code, notes, and snippets.

@mesuutt
Last active October 26, 2021 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mesuutt/62b0091fadf8927d436d5694c899984a to your computer and use it in GitHub Desktop.
Save mesuutt/62b0091fadf8927d436d5694c899984a to your computer and use it in GitHub Desktop.
Check active window every second and run script when window class changed
# ....
# 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
#!/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