The way to create a new window in Safari is to use the command make new document:
make new document at end of documents with properties {URL:the_url}
This will create a new window with one tab pointing to the_url, and make this window the very front. Please note that it make new window at end of windowsdoes not work, and just errors with the "AppleEvent handler do not work."
Similarly, to create a new tab in a window w, you can use make new tab:
make new tab at end of tabs of w with properties {URL:the_url}
w ; the_url, . tabs of w tell w:
tell w
make new tab at end of tabs with properties {URL:the_url}
end tell
, tabs tabs of w.
, script. URL- the_urls, ; the_urls , .
property the_urls : {¬
"http://stackoverflow.com", ¬
"http://tex.stackexchange.com", ¬
"http://apple.stackexchange.com"}
tell application "Safari"
if the_urls = {} then
-- If you don't want to open a new window for an empty list, replace the
-- following line with just "return"
set {first_url, rest_urls} to {"", {}}
else
-- `item 1 of ...` gets the first item of a list, `rest of ...` gets
-- everything after the first item of a list. We treat the two
-- differently because the first item must be placed in a new window, but
-- everything else must be placed in a new tab.
set {first_url, rest_urls} to {item 1 of the_urls, rest of the_urls}
end if
make new document at end of documents with properties {URL:first_url}
tell window 1
repeat with the_url in rest_urls
make new tab at end of tabs with properties {URL:the_url}
end repeat
end tell
end tell