Last active
June 8, 2017 12:54
-
-
Save kelunik/4bcb829d6ee9621502b36dc90b3e30b9 to your computer and use it in GitHub Desktop.
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
#!/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