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 with this contents:

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

Give permissions to this file:
chmod u+x

./ /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.

Deja un comentario