Based on attekei's answer for OSX:
$ brew install fswatch
Chuck all this into reload.scpt
:
function run(argv) {
if (argv.length < 1) {
console.log("Please supply a (partial) URL to reload");
return;
}
console.log("Trying to reload: " + argv[0]);
let a = Application("Google Chrome");
for (let i = 0; i < a.windows.length; i++) {
let win = a.windows[i];
for (let j = 0; j < win.tabs.length; j++) {
let tab = win.tabs[j];
if (tab.url().startsWith("file://") && tab.url().endsWith(argv[0])) {
console.log("Reloading URL: " + tab.url());
tab.reload();
return;
}
}
}
console.log("Tab not found.");
}
That will reload the first tab that it finds that starts with file://
and ends with the first command line argument. You can tweak it as desired.
Finally, do something like this.
fswatch -o ~/path/to/watch | xargs -n1 osascript -l JavaScript reload.scpt myindex.html
fswatch -o
outputs the number of files that have changed in each change event, one per line. Usually it will just print 1
. xargs
reads those 1
s in and -n1
means it passes each one as an argument to a new execution of osascript
(where it will be ignored).