Skip to content

Instantly share code, notes, and snippets.

@yfyf
Last active August 29, 2015 14:19
Show Gist options
  • Save yfyf/f1a7d9edab0f8b02ed69 to your computer and use it in GitHub Desktop.
Save yfyf/f1a7d9edab0f8b02ed69 to your computer and use it in GitHub Desktop.
Inotify wrapper to refresh browser window on file update
#!/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
@yfyf
Copy link
Author

yfyf commented Apr 21, 2015

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