Re: Wait for Load with PDF download in Safari
Re: Wait for Load with PDF download in Safari
- Subject: Re: Wait for Load with PDF download in Safari
- From: Matt Deatherage <email@hidden>
- Date: Mon, 3 Aug 2009 06:11:51 -0500
On 8/2/09 at 8:01 AM, Adam Morris <email@hidden> wrote:
> I was wondering if anyone has found a surefire way to write this
> function that works in every case conceivable?
I don't imagine I can conceive of every case, but the only way I've
found to know if Safari is loading things into the front tab (or
window) is to watch the progress indicator with UI Scripting. Here's
what currently works on one of my systems:
tell application "Safari"
set now to current date
-- Now we use UI Scripting to find the reload/stop button and monitor it
-- This breaks if we rearrange the toolbar :-/
tell application "System Events"
tell process "Safari"
repeat until ((value of attribute "AXDescription" of button 1 of text field 1 of splitter group 1 of group 3 of tool bar 1 of window 1) is not "reload" or ((current date) ≥ (now + 30)))
end repeat
repeat until ((value of attribute "AXDescription" of button 1 of text field 1 of splitter group 1 of group 3 of tool bar 1 of window 1) is not "stop" or ((current date) ≥ (now + 30)))
end repeat
end tell
end tell
end tell
The first repeat loop is necessary because the "Loading" progress
indicator doesn't start immediately upon creating the window. Once
it starts loading, I look for it to change back to "reload," or for
30 seconds to elapse, whichever comes first.
This doesn't work for *downloading* a file (i.e., in the "Downloads"
window), but I believe it works correctly for loading PDF documents
into a window or tab.
--Matt
--
Matt Deatherage <email@hidden>
GCSF, Incorporated <http://www.macjournals.com>
"With us tonight is William Warfield, who is with us tonight.
He is a wonderful man, and so is his wife." -- Eugene Ormandy
_______________________________________________
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