Re: Safari app scripting
Re: Safari app scripting
- Subject: Re: Safari app scripting
- From: Deivy Petrescu <email@hidden>
- Date: Tue, 14 Aug 2018 16:08:27 -0400
> On Aug 13, 2018, at 10:52 , Robert (PT Business Groups)
> <email@hidden> wrote:
>
> Hello list;
>
> An Applescript novice here …..
>
> I use the Safari app in High Sierra and have several scripts that run nicely
> for it.
>
> One small issue that I can’t get past in my scripts is to be able to open a
> new window (make new document) without it accessing the default homepage.
>
> In normal use I want the homepage to open but when using scripts I would like
> the window empty to begin with.
>
> I do have workarounds in place but just wondered if there was something I was
> missing like a simple one liner (just to soothe my curiosity).
>
> Here’s a portion of my ‘basic’ coding that I’ve come up with:
>
>
> "
> tell application "Safari"
> activate -- If this launches Safari then it opens window with default
> homepage tab.
> delay 2.5 -- Need time for the default homepage to load otherwise the
> next step can't close it.
> try
> set taburl to URL of tab 1 of front window
> if taburl starts with "https://www.macintouch" then
> close tab 1 of front window -- This should close the
> window if it has Macintouch as the first and hopefully only tab in the
> window. If not the only tab then it should close just <snip>
> set taburl2 to URL of tab 1 of front window
> if taburl2 starts with "https://www.macintouch" then
> close tab 1 of winlist -- This should close the window if it
> has Macintouch as the first and only tab in the window. If not the only tab
> then it should close just the Macintouch tab.
> end if
> "
>
>
>
> Many thanks in advance.
>
> Robert.
Robert,
The fact that it opens the default homepage in the first tab makes it easy for
you to deal with that.
This is an adaptation of your code:
<script>
tell application "Safari"
activate
set k to make new document -- Opens new window with default homepage
tab.
tell k
open location "https://www.lg.com/"
open location "https://www.netgear.com/"
open location "https://rogueamoeba.com/"
open location "https://www.barebones.com/"
open location "https://bombich.com/"
open location "https://etrecheck.com/"
open location "https://handbrake.fr/"
end tell
tell front window to close tab 1
end tell
</script>
Note, the script assumes you are activating not launching Safari.
There is a bug, that does not let Safari open a window.
Deivy Petrescu
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