-
-
Save assertchris/016ee53bbbef13f3d026eddaa8e49182 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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