Skip to content

Instantly share code, notes, and snippets.

@folkertdev
Created July 3, 2015 19:56
Show Gist options
  • Save folkertdev/d844ae6e260496524d17 to your computer and use it in GitHub Desktop.
Save folkertdev/d844ae6e260496524d17 to your computer and use it in GitHub Desktop.
Reload current chrome tab on a file change
#!/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
@jaderdev
Copy link

Uau man, this is ingenious!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment