• 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: Jim Brandt <email@hidden>
  • Date: Thu, 5 Nov 2009 09:35:00 -0600

Dave,

I was searching AS subjects looking for a discussion I thought I remembered from September
when I noticed your question from back on 28-Sep. Here is a handler I use to detect that a
page is loaded in Safari. It was refined from messages I discovered when I was looking for
the same thing around the first of this year.

The article I found was: http://www.macosxhints.com/article.php?story=20071015132722688

This was I ended up with:

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

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 ------------------------

"static text 1 of window 1" is the text shown at the bottom of the Safari window if you do a
"View>Show Status Bar" command.
• for a brand-new window that hasn't loaded a single item, this text has the value "Untitled"
• if the server is being contacted, the text begins with "Contacting"
• if an item is being sent (i.e. a jpeg or some text), the text begins wit "Loading"
if more than one window is open, then the status bar text could be in
"static text 1 of group 1 of window 1", thus the second variable and the switch.
(I discovered this when the handler failed and I started digging for the reason).

I do several scripts where I need to load a page where I want to print the contents
 to a PDF. These pages sometimes take a fair amount of time to load. I had to have
a reliable way to ensure that they were completely loaded before I tried to print.
This handler works 95-98% of the time.

The wait_secs parameter is the time, in seconds, to wait for the page to load. If the
page hasn't loaded when the wait time has passed, the handler returns with a value
of false.  If the page is loaded, it returns with a value of true.

Hope this helps. Sorry I didn't see this at the time you were asking your question.

Jim Brandt

 _______________________________________________
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: Adding Spotlight Metadata
  • Next by Date: Re: Detecting when URL has been loaded in Safari???
  • Previous by thread: Preserve file info comment when sending a file from a Mac to Windows and the other way around
  • Next by thread: Re: Detecting when URL has been loaded in Safari???
  • Index(es):
    • Date
    • Thread