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:

2 Comments:

At 3:25 AM, Anonymous Anonymous said...

Thanks! That was useful. To prevent the empty first tab: "... make new document with properties {URL: item 1 of urlList}" and then "repeat with currentURL in rest of urlList". (Assuming urlList isn't empty.)

 
At 1:33 PM, Blogger Javier Brolo said...

Hey man... i figured a more reliable way... aparently this code doesn't work anymore in Safari 4. Or at least not on my computer... Plus i haven't got a hang on the Aplescrypt just yet...

Anyway, i think the easiest solution is using automator.
1st. You need to create an html document with the list of links you need. This is easy, if you have them on a spread sheet, just copy paste the list on a text note and save it as html.

Then you need to create an automator flow with just thre items.
- Get Current Webpage from Safari
- Get Link URLs from Webpages (make sure the "only return URLs in the same domain as in the starting page" is chequed off
- Display Webpages

Once you have these two things (the file and the flow), all you have to do is open your .html file with the list and click run on the automator flow.

Cheers.

-J
-

 

Post a Comment

<< Home