Created
July 3, 2015 19:56
-
-
Save folkertdev/d844ae6e260496524d17 to your computer and use it in GitHub Desktop.
Reload current chrome tab on a file change
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
#!/bin/bash | |
# inspired by | |
# http://linux.die.net/man/1/inotifywait | |
# http://razius.com/articles/auto-refreshing-google-chrome-on-file-changes/ | |
# http://unix.stackexchange.com/questions/37258/refresh-reload-active-browser-tab-from-command-line | |
# Usage: | |
# ./chrome-refresh.sh /folder/to/watch /some/folder/file_to_watch.html | |
TIME_FORMAT='%F %H:%M' | |
OUTPUT_FORMAT='%T Event(s): %e fired for file: %w. Refreshing.' | |
RELOAD_KEYS="CTRL+R" | |
BROWSER="google-chrome" | |
CURRENT='' | |
while inotifywait -q -r -e modify --timefmt "${TIME_FORMAT}" --format "${OUTPUT_FORMAT}" "$@"; do | |
sleep .5s # lets a flask server catch up with the file change | |
CURRENT=$(xdotool getactivewindow) | |
xdotool search --class ${BROWSER} windowactivate --sync | |
xdotool search --class ${BROWSER} key --clearmodifiers ${RELOAD_KEYS} | |
xdotool windowfocus --sync ${CURRENT} | |
xdotool windowactivate --sync ${CURRENT} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uau man, this is ingenious!