Auto Reload/Refresh Browser Tab

134 views
Skip to first unread message

Jason Underdown

unread,
May 22, 2016, 4:43:28 PM5/22/16
to MathBook XML Support
Hi Everyone,

In my quest for efficiency, I found that I was spending way too much time switching from Emacs to Chrome and then refreshing the browser tab which displays my HTML output. I realized that I needed to have my computer do this work for me. After much Googling I decided to use a utility called fswatch, which as the name implies, watches the filesystem for changes to files. The following instructions are for Mac users, but since fswatch is cross-platform, I imagine the following can be adapted to Linux as well. (Probably just need to change the code in between "do" and "done" in the Bash script below as it is specific to Mac OS X.)

Information on fswatch can be found at: http://emcrisostomo.github.io/fswatch/

1. Install fswatch. I use homebrew which is the de-facto package manager for Mac. (See http://brew.sh) Obviously you will need to install homebrew if you do not already have it on your system.

$ brew install fswatch

2. Save the following Bash script under the name "reload" in the same directory where you keep your source XML files:

#!/bin/bash
fswatch -o ../out/html/*.html | while read num
do
  osascript -e 'tell application "Google Chrome" to reload active tab of window 1'
  osascript -e 'say "Page reloaded master" using "Zarvox"'
done

3. Make the "reload" script you just created executable by typing the following in a terminal:

$ chmod a+x reload

4. Change the path: "../out/html*.html" in the script above to the path that gets you from your src directory to your HTML output directory. Be sure to save your changes to the "reload" script.

5. In a terminal, cd to your src directory where you saved the "reload" script and type:

$ ./reload

At this point, every time you use make to build your HTML files, the browser tab displaying the HTML file should automatically get refreshed. Actually the script will reload the currently active tab, but as long as your project is the currently active tab in Google Chrome, it will get reloaded.

Cheers,
Jason


Rob Beezer

unread,
May 23, 2016, 12:50:46 AM5/23/16
to mathbook-x...@googlegroups.com
Dear Jason,

Thanks for the tips. I've got one of my own in a minute. I'd be great to
collect these into the documentation material for emacs.

My PDF viewer (okular) does something similar to fswatch so I really like that
functionality.

Rob
> --
> You received this message because you are subscribed to the Google Groups
> "MathBook XML Support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to mathbook-xml-sup...@googlegroups.com
> <mailto:mathbook-xml-sup...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Jason Underdown

unread,
May 23, 2016, 11:50:00 AM5/23/16
to MathBook XML Support, bee...@ups.edu
Yep, I'm OK with PDF as well because Skim integrates nicely in my LaTeX workflow. 

The problem is specifically with HTML. There are lots of simple extensions for all of the browsers that will periodically reload a page, but none that I'm aware of that can actually check for local filesystem changes, and only refresh the page when the local filesystem changes.

Keller, Mitch

unread,
May 25, 2016, 3:25:25 PM5/25/16
to mathbook-x...@googlegroups.com
Ooh, this is fun. For those who use Safari, the Applescript dictionary is a bit different. Making your reload script read as follows will work, however:

#!/bin/bash
fswatch -o ../out/html/*.html | while read num
do
osascript -e 'tell application "Safari"
set docUrl to URL of document 1
set URL of document 1 to docUrl
end tell'

osascript -e 'say "Page reloaded master" using "Zarvox”’

done

Firefox doesn’t seem very amenable to Applescript, so I can’t provide an alternative there. (You could use some Applescript code to send a cmd-r to Firefox, but that requires activating Firefox, which means that you’ll suddenly jump over to your browser instead of continuing to work where you are while being alerted to the fact that your browser tab has been reloaded.)
> --
> You received this message because you are subscribed to the Google Groups "MathBook XML Support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mathbook-xml-sup...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
Mitch Keller
Assistant Professor of Mathematics
Washington & Lee University, Lexington VA
206 Robinson Hall ~ 540.458.8099 ~ http://www.rellek.net

Reply all
Reply to author
Forward
0 new messages