Quantcast
Channel: Recent Gists from assertchris
Viewing all articles
Browse latest Browse all 30

focus-switch.sh

$
0
0
focus-switch.sh
#!/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

Viewing all articles
Browse latest Browse all 30

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>