auto-reload html file with a browser via terminal command
You can use AppleScript to reload the tab. See the Benjie's answer for this question
Use osascript
to call the AppleScript from shell script. You'll get something like this:
osascript -e 'tell application "Google Chrome" to tell the active tab of its first window to reload'
Alternatively you can use something like next to close all previous tabs:
tell application "Google Chrome"
set windowList to every tab of every window whose URL starts with "http://stackoverflow.com"
repeat with tabList in windowList
repeat with thisTab in tabList
close thisTab
end repeat
end repeat
end tell
If there is already a tab for foo.html
, open foo.html
should focus that tab in Safari. For Chrome, you might use something like this:
set u to "http://t.co/"
tell application "Google Chrome"
repeat with w in windows
set i to 0
repeat with t in tabs of w
set i to i + 1
if URL of t is u then
set active tab index of w to i
set index of w to 1
tell t to reload
activate
return
end if
end repeat
end repeat
open location u
activate
end tell
I have just assigned ⌘R to open "$TM_FILEPATH" -a Safari
in the text.html
scope in TextMate. I have also enabled saving documents when switching to another application, so it basically does the last three steps of the edit-save-switch application-refresh cycle.
Other options:
- http://livereload.com
- http://brettterpstra.com/2011/03/07/watch-for-file-changes-and-refresh-your-browser-automatically