MACSCRPT Archives

August 2011

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Christopher Stone <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 30 Aug 2011 11:01:48 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (43 lines)
On Aug 30, 2011, at 07:02, Ed Graf wrote:
> I thought I read it here a while ago but cannot find a reference so far... Using Applescript, if possible, how can one reliably detect that a URL request has been fully loaded in Safari?

______________________________________________________________________

Hey Ed,

I haven't used this for a while and not on Lion.
The delay values may need some tweaking to achieve complete reliability.

--
Best Regards,
Chris

-------------------------------------------------------------------------------
on page_loaded(timeout_value)
  delay 2
  repeat with i from 1 to the timeout_value
    tell application "Safari"
      if (do JavaScript "document.readyState" in document 1) is "complete" then
        return true
      else if i is the timeout_value then
        return false
      else
        delay 1
      end if
    end tell
  end repeat
  return false
end page_loaded
-------------------------------------------------------------------------------
tell application "Safari"
  # activate
  # LOAD URL
  make new document with properties {URL:SITE_URL}
  set bounds of front window to {0, 22, 1038, 1024}
  # WAIT FOR LOADING COMPLETE
  page_loaded(1) of me
  delay 1.5
  set docSource to source of document 1
end tell
-------------------------------------------------------------------------------

ATOM RSS1 RSS2