Re: Open Safari and Script
Re: Open Safari and Script
- Subject: Re: Open Safari and Script
- From: "Mark J. Reed" <email@hidden>
- Date: Sat, 29 Dec 2007 08:58:24 -0500
Ah. So there may be a race condition causing the (tell (make new
document)) to fail because the ref returned by the (make new document)
command is to a blank document that is almost immediately replaced by
the user's home page or whatever. So a simple "make new document
with properties" may be the most straightforward approach. You can
prepend the "close windows" bit, but of course that's not ideal if you
might have open Safari windows you want to keep around. If you want
to use an existing browser window without closing the others or
opening a new one, Emmanuel's code will help.
Lots of valuable info in this thread. Thanks!
On 12/29/07, Emmanuel <email@hidden> wrote:
> At 12:18 PM +0000 12/29/07, Nigel Garvey wrote:
> >I wrote on Sat, 29 Dec 2007 11:34:55 +0000:
> >
> >>It seems
> >>more reliable to use an index reference instead:
> >>
> >> tell application "Safari"
> >> if (count of windows) is greater than 0 then close windows
> >> make new document
> >> set URL of document 1 to "http://www.macscripter.net/"
> >> end tell
> >
> >Or possibly:
> >
> > tell application "Safari"
> > if (count of windows) is greater than 0 then close windows
> > make new document with properties {url:"http://www.macscripter.net/"}
> > end tell
>
> Popping by in a thread I didn't follow, I mention (as a frequent
> scripter of Safari) that Safari has several kinds of windows, and you
> may want to let open those which are not browser windows (Downloads,
> Activity, possibly Javascript Console, etc.)
>
> In case it helps, here is an excerpt of a working script which does
> its best to figure out whether Safari has a browser window available
> - and to get a reference to it:
>
> -- over-tested --------------
> tell application "Safari" to set n to (count windows)
> set windindex to -1
> repeat with i from 1 to n
> try
> tell application "Safari" to get source of document i
> set windindex to i
> exit repeat
> end try
> end repeat
> if windindex is -1 then error "No browser window is available." from ""
> -----------------------------
>
> Let the rights on this wonderful piece of code be my New Year gift to
> the AppleScript community.
>
> Emmanuel
> _______________________________________________
> 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
>
--
Mark J. Reed <email@hidden>
_______________________________________________
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