Wednesday, September 18, 2019

#1 2019-08-30 07:17:09 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 538

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:

Applescript:


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.

Last edited by KniazidisR (2019-09-10 11:52:34 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

#2 2019-09-01 05:21:35 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5005

Re: Auto Refreshing the Current Web 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.


NG

Offline

 

#3 2019-09-10 11:50:39 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 538

Re: Auto Refreshing the Current Web Page

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.


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)