• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Detecting when URL has been loaded in Safari???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting when URL has been loaded in Safari???


  • Subject: Re: Detecting when URL has been loaded in Safari???
  • From: Roy Whelden <email@hidden>
  • Date: Thu, 5 Nov 2009 09:12:00 -0800

Dave,
Would it not be easier to use the Safari 'do _javascript_' command, as in:
-------------------------------------------
tell application "Safari"
set the URL of the front document to "http://some.web.page"
delay 2 --the page begins loading
repeat with i from 1 to 20--check 20 times
if (do _javascript_ "document.readyState" in document 1 is "complete" then
exit repeat--the page has successfully loaded
else
delay 1
end if
end repeat--go back and check again after the one second delay
end tell
---------------------------------------------
This script is shorter, at least. You might add some 'try ..... end try'  statements to catch errors.


Roy

==========Your script=========
on check_Safari_page_loaded(wait_secs)
set loaded to false
set cnt to 0
repeat until loaded
set cnt to cnt + 1
delay 0.5
tell application "System Events" to ¬
tell process "Safari"
set x to (value of static text 1 of window 1 as text)
set y to ""
if exists group 1 of window 1 then
if exists (static text 1 of group 1 of window 1) then set y to (value of static text 1 of group 1 of window 1 as text)
end if
if y = "" then
set w_Name to x
else
set w_Name to y
end if
set loading to false
if (w_Name begins with "Contacting") then set loading to true
if (w_Name begins with "Loading") then set loading to true
if (w_Name begins with "Untitled") then set loading to true
if loading and not (cnt > (wait_secs * 2)) then
set loaded to false
else
set loaded to true
exit repeat
end if
end tell -- process Safari
end repeat
if cnt > wait_secs * 2 then set loaded to false
return loaded
end check_Safari_page_loaded

------------------------ check_Safari_page_loaded handler ------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Detecting when URL has been loaded in Safari???
  • Next by Date: Error -609
  • Previous by thread: Re: Detecting when URL has been loaded in Safari???
  • Next by thread: Error -609
  • Index(es):
    • Date
    • Thread