10.6: An AppleScript to check complete page loading in Safari

Nov 10, '09 07:30:00AM

Contributed by: Anonymous

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.

repeat
  delay 0.5
  tell application "System Events" to ¬
    tell application process "Safari"
      set a to get properties of button 1 of text field 1 of splitter group 1 of group 2 of tool bar 1 of window 1
          set b to accessibility description of a
      
      if b contains "stop" then
        ---say "loading"
      else
        say "loaded"
        exit repeat
      end if
    end tell
end repeat
[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).]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20091101035318405