Archivo por meses: abril 2020

Bash: watch file/directory changes and refresh browser

By using inotifywait, xwininfo, and xdotool, you can keep watching for directory/file changes and send an F5 key stroke to a selected window (i.e. your browser)

First, create a file called browser_watch.sh with this contents:

#!/bin/bash
file=$1
SELECTED_WID=$(($(xwininfo | grep "Window id" | cut -d " " -f 4)))
while inotifywait -r -e close_write $file; do
echo "File changed... Sending F5 to window id=$SELECTED_WID"
CURRENT_WID=$(xdotool getwindowfocus)
xdotool windowactivate $SELECTED_WID
xdotool key F5
xdotool windowactivate $CURRENT_WID
done

Give permissions to this file:
chmod u+x browser_watch.sh

Example:
./browser_watch.sh /path/to/watch

When you run this file, you first will need to click the browser window where the F5 strokes will be sent to.

That is! When a file is changed under the given path, an F5 stroke will be sent to the browser window.