Skip to content

Instantly share code, notes, and snippets.

@assertchris
Forked from kelunik/focus-switch.sh
Created June 8, 2017 12:54
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 assertchris/016ee53bbbef13f3d026eddaa8e49182 to your computer and use it in GitHub Desktop.
Save assertchris/016ee53bbbef13f3d026eddaa8e49182 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function is_browser {
local path=$1
local basename=$(basename $path)
if [[ $basename = "chromium-browser" ]]; then
return 1
fi
return 0
}
browser=0
while true; do
filename=$(inotifywait -qre modify -e create -e move -e delete --format %f .)
printf "%s changed, awaiting switch to browser" $filename
echo ""
while [[ $browser = "0" ]]; do
current_process=$(ps -p $(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}') _NET_WM_PID | awk '{print $3}') -o command= | awk '{print $1}')
is_browser $current_process
if [[ $? -eq 1 ]]; then
if [[ $browser = "0" ]]; then
browser=1
echo "Switched to browser..."
# Execute program here...
echo "Done."
fi
fi
sleep 1
done
browser=0
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment