Created
June 24, 2020 13:12
-
-
Save felixgolcher/7127c798671315f5dfd3f1b7f3f8b61d to your computer and use it in GitHub Desktop.
reload.sh file.html titlebit; reloads file.html in a browser window when changed. Tested only on xfce/manjaro.
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 -x | |
# Wed 24 Jun 2020 02:39:13 PM CEST | |
# [email protected] | |
# heavily based on | |
# https://unix.stackexchange.com/questions/37258/refresh-reload-active-browser-tab-from-command-line | |
# L Nix <[email protected]> | |
# reload browser window | |
# useage: reload.sh file titlebit | |
# file: the file loaded in the browser | |
# titlebit: Some unique part of the browser window title | |
FILETOWATCH=$1 | |
# whether to use SHIFT+CTRL+R to force reload without cache | |
RELOAD_KEYS="F5" | |
# RELOAD_KEYS="CTRL+R" | |
# RELOAD_KEYS="SHIFT+CTRL+R" | |
# | |
# set to whatever's given as argument | |
NAMEBIT=$2 | |
# | |
# if was empty, default set to name of browser, firefox/chrome/opera/etc.. | |
if [ -z "${NAMEBIT}" ]; then | |
NAMEBIT=Mozilla | |
fi | |
# | |
echo $NAMEBIT | |
while inotifywait -e close_write $FILETOWATCH; | |
do sleep 1 | |
# get which window is active right now | |
MYWINDOW=$(xdotool getactivewindow) | |
# | |
# bring up the browser | |
xdotool search --name ${NAMEBIT} windowactivate --sync | |
# send the page-reload keys (C-R) or (S-C-R) | |
xdotool search --name ${NAMEBIT} key --clearmodifiers ${RELOAD_KEYS} | |
# | |
# sometimes the focus doesn't work, so follow up with activate | |
xdotool windowfocus --sync ${MYWINDOW} | |
xdotool windowactivate --sync ${MYWINDOW} | |
date +%Y-%m-%d_%H%M | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment