Last active
August 29, 2015 14:19
-
-
Save yfyf/f1a7d9edab0f8b02ed69 to your computer and use it in GitHub Desktop.
Inotify wrapper to refresh browser window on file update
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 | |
set -euo pipefail | |
FILE=$1 | |
FILENAME=$(basename "$FILE") | |
BROWSER=iceweasel | |
OK=0 | |
while [ $OK -eq 0 ]; do | |
inotifywait -e close_write -q $FILE >/dev/null | |
OK=$? | |
echo "$(date --rfc-3339=seconds) Refresh: $FILENAME" | |
CUR_WID=$(xdotool getwindowfocus) | |
# Try to find a specific window with the filename in the (HTML) title, | |
# otherwise select the first visible browser window. | |
WID1=$(xdotool search --name "$FILENAME.*$BROWSER"|head -1 || echo "") | |
WID=$(xdotool search --onlyvisible --class $BROWSER|head -1) | |
if [[ -z "$WID" ]]; then echo "Using first" && WID=$WID1; fi | |
echo "Refreshing window: \"$(xdotool getwindowname $WID)\"" | |
xdotool key --window $WID 'F5' | |
xdotool windowactivate $CUR_WID | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from: http://peter-hoffmann.com/2010/refresh-browser-on-save-with-inotify-and-xdotool.html