Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: An AppleScript to check complete page loading in Safari Web Browsers
Snow Leopard only hintThis code will basically run until the currently-loading page is done loading in Safari. This code is working in Safari 4.0.3 running on OS X 10.6; I haven't tested in other versions of Safari or the OS. [robg adds: To use this script, save it to your user's Library » Scripts » Applications » Safari folder (create any of those folders if they don't exist). I'm not positive, but I think the idea here is that you can use this script if you're on a very slow connection and/or trying to load a very slow-loading page. Just put the URL into Safari, press Return, then run the above script via the Script menu item. You can then just wait for your Mac to say loaded when the page is done loading.

I had trouble finding a site that would load slowly enough to let me invoke the script, but I eventually found one; the script works as described in 10.6 (it won't compile in 10.5).]
    •    
  • Currently 1.82 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (17 votes cast)
 
[9,348 views]  

10.6: An AppleScript to check complete page loading in Safari | 4 comments | Create New Account
Click here to return to the '10.6: An AppleScript to check complete page loading in Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: An AppleScript to check complete page loading in Safari
Authored by: Stef@nK on Nov 10, '09 09:53:50AM
This this a different approach which works also in Tiger (Safari 3 and higher required) and Leopard and avoids GUI scripting

tell application "Safari" to open location "http://www.macosxhints.com/article.php?story=20091101035318405"
if page_loaded(20) then
	say "loaded"
else
	say "failed"
end if

on page_loaded(timeout_value) -- in seconds
	delay 1
	repeat with i from 1 to timeout_value
		tell application "Safari"
			if name of current tab of window 1 is not "Loading" then exit repeat
		end tell
		delay 1
	end repeat
	if i is timeout_value then return false
	tell application "Safari"
		repeat until (do JavaScript "document.readyState" in document 1) is "complete"
			delay 0.5
		end repeat
	end tell
	return true
end page_loaded


[ Reply to This | # ]
10.6: An AppleScript to check complete page loading in Safari
Authored by: redfood on Nov 10, '09 10:07:56AM
To work under 10.5 just the line
  set b to accessibility description of a
to
  set b to help of a
Also it should be noted that the apple script only works if "enable access for assistive devices" is checked in the "Universal Access" pane of the preferences.

[ Reply to This | # ]
10.6: An AppleScript to check complete page loading in Safari
Authored by: redfood on Nov 10, '09 10:09:28AM

Sorry, that should have read "To work under 10.5, just change the line"



[ Reply to This | # ]
10.6: An AppleScript to check complete page loading in Safari
Authored by: nikmagnus on Jul 12, '12 08:48:05PM

I tried this and it works where many other solutions do not.
Most other solutions based on javascript worked in 10.5, but not in 10.6 and regarded the page as loaded even if the blue line of hope (loading complete bar) has reached the far right.
I am truly grateful.
Nik (Cygnet, Tasmania, Australia)



[ Reply to This | # ]