Tumblr posting script revisited

I’ve made some fixes to my Post To Tumblr script to make it more reliable. I found that many newsfeeds don’t have a summary property, so I’m using description instead, which is more correct. I’m also testing the existence of all properties before I use them.

Here’s the updated script. You can also download it here.

on urlencode(x)
	set TheCode to do shell script "python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of (x)
	return TheCode
end urlencode

tell application "NetNewsWire"
	if title of selectedHeadline exists then
		set q_title to my urlencode(title of selectedHeadline)
	else
		set q_title to "Untitled"
	end if

	if permalink of selectedHeadline exists then
		set q_url to my urlencode(permalink of selectedHeadline)
	else
		set q_url to ""
	end if

	if description of selectedHeadline exists then
		set q_content to my urlencode(description of selectedHeadline)
	else
		set q_content to ""
	end if

	set tumblr to "http://www.tumblr.com/share?v=3&u=" & q_url & "&t=" & q_title & "&s=" & q_content
	open URL in new tab with tumblr

end tell

Leave a Reply