Chibimagic's Weblog

Posts Tagged ‘code applescript netnewswire

I subscribe to tweets in NetNewsWire, and I’ve been annoyed that there’s no quick and simple way to load URLs that people post. You have to grab the mouse, highlight the text, copy, tab to Safari, then paste and hit enter. I wrote this so that I wouldn’t have to take my hands off the mouse.

set URLtoopen to ""
tell application "NetNewsWire"
	set feedName to display name of selectedSubscription
	if feedName is "Twitter" then
		set headlineContents to title of selectedHeadline
		set oldtid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to space
		repeat with titleword in text items of headlineContents
			try
				if word 1 of titleword is "http" then
					set URLtoopen to titleword as string
					exit repeat
				end if
			end try
		end repeat
		set AppleScript's text item delimiters to oldtid
	end if
end tell
if URLtoopen is not "" then
	tell application "Safari" to open location URLtoopen
end if

I saved a copy of it in NetNewsWire’s scripts folder, and set up a keyboard shortcut of Command-Right Arrow in the Keyboard & Mouse pane of System Preferences. Now I can quickly load URLs that everyone posts. This only grabs the first URL in the post, since I’ve never seen more than one per post, and I don’t think there’s room for more than one anyway.

The code gets cut off by the theme I’m using, but copy paste should work if you want to use it.