Skip to content

Instantly share code, notes, and snippets.

@razius
Last active November 6, 2018 13:50
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save razius/8503625 to your computer and use it in GitHub Desktop.
Save razius/8503625 to your computer and use it in GitHub Desktop.
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
@AmarPrabhu
Copy link

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