Auto Refreshing the Current Web Page

I wrote the following script to track every 5 minute changes on “AppleScript|Mac OS X” forum of MacScripter site, but you can track changes on any web page. Save the script as stay-open application and run it when you want:


on run
	-- set theURL to "https://www.macscripter.net/viewforum.php?id=2"
	-- tell application "Safari" to open location theURL
end run

on idle
	tell application "Safari"
		activate
		tell window 1 to (do JavaScript "window.location.reload(true)" in current tab)
	end tell
	return 300
end idle

NOTE: If you want to open automatically and track only 1 specific page, then uncomment the 2 code lines in the on run handler and insert your link to this page.

Hi KniazidisR.

Thanks for the tip. Hopefully MacScripter’s 30,000+ members won’t all use it at once. :wink:

Your run, idle, and quit handlers don’t need the braces in their top lines — the run handler because its parameters are optional and don’t need a placeholder, the other two because they don’t take parameters anyway.

Also, your quit handler’s not actually needed, since it only contains continue quit. A quit handler’s basically an intercept for any quit command the applet receives. If you want the script to carry out additional tasks before the applet actually quits, you use a quit handler containing the appropriate instructions and ending with continue quit. Otherwise the handler’s not needed. The app will finish what it’s doing and quit in the normal way.

See Handlers in Script Applications in the AppleScript Language Guide.

I updated the script according to fair remarks. Also, I increased the time interval to 5 minutes - so as not to load the page with multiple requests.