Open lines in clipboard as URLs in Safari

Alec Jacobson

November 14, 2009

weblog/

I used to use a script that took the lines of a text edit document and opened each as a url in Safari. This was useful when I used text-edit. Now I'm using Terminal and other apps to gather urls so its easier and more general to just copy the urls to the clipboard (CMD + C) and run this script. The applescript below opens each line of the copied text as a new safari window setting the line as the url.
set clipboard_contents to the clipboard as text
set urlList to paragraphs of clipboard_contents
set numURLs to (count urlList)
tell application "Safari"
	activate
	repeat with this_url in urlList
		if length of this_url is greater than 0 then
			set this_doc to make new document at end of documents
			set URL of this_doc to this_url
		end if
	end repeat	
end tell
Note: There are lots of hacks to open a list of urls as tabs, find one and use it if your desire tabs. I didn't post this for tabs because as far as I know opening a bunch of tabs always requires and awkward hack like using system events and keystrokes etc.