Skip to content
Advertisement

Looking for a simple way to watch files, run a script, and refresh the browser

File is edited. File is saved. Bash script is run upon save. Browser refreshes itself to automatically show the changes.

Windows, OS X, Linux

Any suggestions? This seems like such an important thing that’s constantly overlooked, and I would greatly appreciate learning how to achieve this between all major OSes.

Thanks, in advance.

Advertisement

Answer

There are a few options. One is to use entr on Linux and OSX – website is here. Then your command is:

JavaScript

An alternative to entr is to use fswatch or inotifywait – the syntax is pretty similar. I believe you can use fswatch on Windows too.

Then we come onto the question of the browser refresh. It is going to be dependent on the browser and the OS. On OSX, you can use Applescript like this for Safari:

JavaScript

And with Google Chrome on OSX, you could use:

JavaScript

On Linux, you can use xdotool as described here.

By the way, on OSX, I would install entr and fswatch with homebrew using:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement