|
|
An AppleScript to check complete page loading in Safari
curses! Safari 4 breaks this technique; it no longer sets the title differently as it loads.
An AppleScript to check complete page loading in Safari
I adjusted the original poster's technique by simply checking for a closing html tag... not exactly bullet proof, but for now this will keep my various browser-based scripts working.
I encourage others out there to come up with a more reliable method than my little hack here. thanks folks. ----------- SafariLoad("http://www.macintouch.com/") on SafariLoad(theURL) -- this routine attempts to load a Safari page to completion, and returns the final title local theVersion, thedocument, thewindow, theSource, thetab, theTitle -- check to see if we should open a new URL or just wait for the existing window to load tell application "Safari" set theVersion to version set theVersion to (character 1 of theVersion) as number if theURL ≠"" then set thedocument to (make new document) as reference set URL of thedocument to theURL end if --check to see if page has finished loading repeat -- let the script breathe for a second delay 1.0 -- Safari version 3 and version 4 have different techniques for determining load completion if theVersion = 3 then if (name of thedocument as text) ¬ begins with "Contacting" or (name of thedocument as text) begins with "Loading" or (name of thedocument as text) begins with "Waiting" then else exit repeat end if end if -- Safari version 4 no longer updates the page title based on progress -- this cheap and dirty technique below *requires* that the target URL contains a closing HTML tag -- this is highly unreliable for accessing pages that you do not control -- however, this completion check is technically accurate from an HTML standpoint, even if not from that of HTTP if theVersion = 4 then set thewindow to front window set thetab to current tab of thewindow set theSource to source of thetab -- if the page has not started loading, safari will error out when accessing the page source -- allow for that error and simply retry try if (theSource contains "</html>") then exit repeat end if end try end if end repeat end tell copy (name of document 1) to theTitle return theTitle end SafariLoad
An AppleScript to check complete page loading in Safari
I adjusted the original poster's technique by simply checking for a closing html tag... not exactly bullet proof, but for now this will keep my various browser-based scripts working.
I encourage others out there to come up with a more reliable method than my little hack here. thanks folks. ----------- SafariLoad("http://www.macintouch.com/") on SafariLoad(theURL) -- this routine attempts to load a Safari page to completion, and returns the final title local theVersion, thedocument, thewindow, theSource, thetab, theTitle -- check to see if we should open a new URL or just wait for the existing window to load tell application "Safari" set theVersion to version set theVersion to (character 1 of theVersion) as number if theURL ≠"" then set thedocument to (make new document) as reference set URL of thedocument to theURL end if --check to see if page has finished loading repeat -- let the script breathe for a second delay 1.0 -- Safari version 3 and version 4 have different techniques for determining load completion if theVersion = 3 then if (name of thedocument as text) ¬ begins with "Contacting" or (name of thedocument as text) begins with "Loading" or (name of thedocument as text) begins with "Waiting" then else exit repeat end if end if -- Safari version 4 no longer updates the page title based on progress -- this cheap and dirty technique below *requires* that the target URL contains a closing HTML tag -- this is highly unreliable for accessing pages that you do not control -- however, this completion check is technically accurate from an HTML standpoint, even if not from that of HTTP if theVersion = 4 then set thewindow to front window set thetab to current tab of thewindow set theSource to source of thetab -- if the page has not started loading, safari will error out when accessing the page source -- allow for that error and simply retry try if (theSource contains "</html>") then exit repeat end if end try end if end repeat end tell copy (name of document 1) to theTitle return theTitle end SafariLoad |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.05 seconds |
|