How do you open 100 URLs with one click?

I had reason to load dozens and dozens of URLs from a list into the browser. Obviously it’s a pain to try to copy and paste each one. A little googling led me to this handy little bit of AppleScript. It turns out AppleScript is SUPER needy and so you really have to get the write syntax. Line breaks count as breaks rather than pauses. Which is annoying but here you go.

Just substitute the example.com for whatever you want:


property the_urls : {¬
"http://example.com", ¬
"http://example.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