Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Watches the folder or files passed as arguments to the script and when detects a change it automatically refreshes the current selected Chrome tab or window.
#!/bin/bash
#
# Watches the folder or files passed as arguments to the script and when it
# detects a change it automatically refreshes the current selected Chrome tab or
# window.
#
# http://razius.com/articles/auto-refreshing-google-chrome-on-file-changes/
#
# 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.'
while inotifywait -q -r --timefmt "${TIME_FORMAT}" --format "${OUTPUT_FORMAT}" "$@"; do
CHROME_WINDOW_ID=$(xdotool search --onlyvisible --class google-chrome | head -1)
xdotool key --window $CHROME_WINDOW_ID 'CTRL+r'
done

You can also use

xdotool search "Google Chrome" windowactivate --sync key --clearmodifiers ctrl+r

Stumbled upon thiswhile trying to achieve something similar. Thanks :)

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