An Obsession with Everything Else

http://www.derrickschneider.com/atom.xml

Friday, March 21, 2008

AppleScript: Open A Bunch Of Links In Safari

I recently judged the American Wine Blog Awards. My list of nominees came as a spreadsheet with the URLs of the blogs and their names, grouped by category. Because there were 30 or more nominations in some categories, I didn’t want to open each link individually in Safari. I turned to my old friend and nemesis: AppleScript.

It took a bit of online sleuthing to figure out the quirks in Safari’s dictionary, but I eventually got a script that opens a set of URLs, each in its own tab, in a new window. I’ve included it below for anyone who might find it useful. It works well enough, given that I only needed to run it 8 times. It’s pretty brain dead as it is: There is no error checking and you have to have the URLs in a return-delimited list, which is what you get when you copy URLs out of a column in Excel. If you run it, you’ll also notice that it opens an extra tab at the “beginning” of the new window. If it bothered me, I would figure out how to remove the tab, but for 8 runs I could just click the close box. I only tested it on Mac OS X 10.5 and Safari 3.0.




set clipText to the clipboard

set AppleScript's text item delimiters to {"
"}
set urlList to text items of clipText
set AppleScript's text item delimiters to {""}
tell application "Safari"
set newDoc to make new document
set currWindow to front window
repeat with currentURL in urlList
make new tab at the end of tabs in currWindow with properties {URL:currentURL}
end repeat
end tell

Labels:

0 Comments:

Post a Comment

<< Home