Re: if the document named (.........) exists
Re: if the document named (.........) exists
- Subject: Re: if the document named (.........) exists
- From: Christopher Stone <email@hidden>
- Date: Sat, 11 May 2019 19:39:04 -0500
On 05/08/2019, at 16:38, William Seabrook <email@hidden
<mailto:email@hidden>> wrote:
> Here is an extract from a script to request the load a web page in Safari,
> and wait until it is complete before continuing:
Hey Bill,
In general you're better off if you can test for a specific element toward the
bottom of your given web page(s) with JavaScript.
Ed and Simon have given you useful advice, but neither of those methods is
truly reliable.
That said they may be good enough for your purposes.
We spent a LOT of time working this problem on the Keyboard Maestro Forum a few
years back.
My own script for Safari is similar to Simon's, but I have a couple of
embellishments:
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2012/04/21 23:32
# dMod: 2019/05/11 19:25
# Appl: Safari
# Task: Wait for Safari page to stop loading before continuing.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @Page, @ReadyState, @Loading, @Finish,
@Completes, @Handler
------------------------------------------------------------
set siteURL to "https://www.macupdate.com <https://www.macupdate.com/>"
tell application "Safari"
activate
make new document with properties {URL:siteURL}
set bounds of front window to {228, 23, 1542, 1196}
set initialDelay to 2
set timeoutValue to 60
if SAFARI_PAGE_LOADED(initialDelay, timeoutValue) of me then
display notification "Front Page Loaded!" with title "Safari" subtitle
"" sound name "Tink"
# DO STUFF
else
error "Problem loading page in Safari!"
end if
end tell
------------------------------------------------------------
--ยป HANDLERS
------------------------------------------------------------
on SAFARI_PAGE_LOADED(initialDelay, timeoutValue)
delay initialDelay
repeat with i from 1 to the timeoutValue
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is
"complete" then
return true
else if i is the timeoutValue then
return false
else
delay 0.5
end if
end tell
end repeat
return false
end SAFARI_PAGE_LOADED
------------------------------------------------------------
You'll have to post more information if you want to look into the element-based
JavaScript solution.
--
Best Regards,
Chris
_______________________________________________
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