An AppleScript to send from NetNewsWire 3.1.1 to Tumblr

Jan 29, '08 07:30:01AM

Contributed by: majestic07

Here's an Applescript that sends the currently selected headline from NetNewsWire 3.1.1 to Tumblr. It does little error checking, and requires the user to create a new keychain key for http://www.tumblr.net, as there is some issue with the .com domain that I haven't figured out yet.

tell application "NetNewsWire"
  set NNWURL to (URL of selectedHeadline)
  set NNWTitle to (title of selectedHeadline)
  set NNWSummary to (paragraph 1 of (get description of selectedHeadline & "…"))
end tell

tell application "Keychain Scripting"
  set tumblr_key to first Internet key of current keychain whose server is "www.tumblr.net"
  set tumblr_login to ("email=" & account of tumblr_key & "&password=" & password of tumblr_key)
end tell

set tumblrPostType to {"regular", "link", "quote"}
set postType to (choose from list tumblrPostType)

if postType as string is "regular" then
  set tumblrTitle to the text returned of (display dialog "Enter Title for Text (required):" default answer "Title")
  set tumblrBody to the text returned of (display dialog "Enter Body for Text (may contain basic html - links, bold, etc.):" default answer "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras aliquam, elit vel imperdiet pretium, nulla eros dictum nibh, ac aliquet velit felis at mauris. Nam fringilla, nisl at sagittis tempor, magna magna porttitor nibh, id vehicula mauris nulla vestibulum nunc. Sed neque. Duis tincidunt magna sit amet purus. Cras purus nisi, gravida sodales, posuere vel, varius ut, odio. Aliquam erat volutpat. Aenean aliquam. Proin rhoncus magna. In tempor. Aenean non justo et orci nonummy malesuada. Pellentesque neque. Nulla facilisi. Morbi enim augue, porttitor eu, blandit a, vestibulum sed, arcu. Mauris interdum. Donec a odio. Ut volutpat augue non justo. Morbi.")
  set send to ("title=" & tumblrTitle & "&body=" & tumblrBody)
  display dialog (postType as string) & ":
" & tumblrTitle & ":
" & tumblrBody
  
else if postType as string is "quote" then
  set tumblrSource to the text returned of (display dialog "Enter Source for Quote:" default answer "")
  set tumblrQuotation to the text returned of (display dialog "Enter Quotation:" default answer "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras aliquam, elit vel imperdiet pretium, nulla eros dictum nibh, ac aliquet velit felis at mauris. Nam fringilla, nisl at sagittis tempor, magna magna porttitor nibh, id vehicula mauris nulla vestibulum nunc.")
  set send to ("quote=" & tumblrQuotation & "&source=" & tumblrSource)
  display dialog (postType as string) & ":
" & tumblrQuotation & ":
" & tumblrSource
  
else if postType as string is "link" then
  set tumblrTitle to the text returned of (display dialog "Enter Title for Link:" default answer NNWTitle)
  set tumblrURL to the text returned of (display dialog "Enter URL for a Tumblr Link:" default answer NNWURL)
  set tumblrDescription to the text returned of (display dialog "Enter a description for this link:" default answer NNWSummary)
  set send to ("url=" & tumblrURL & "&name=" & tumblrTitle & "&description=" & tumblrDescription)
  display dialog (postType as string) & ":
" & tumblrTitle & ":
" & tumblrURL
end if

set tumblrPost to the quoted form of (tumblr_login & "&generator=NNW-AppleScript&type=" & postType & "&" & send)
do shell script ("curl --data-binary " & tumblrPost & " http://www.tumblr.com/api/write")
At this time, this only allows three of the seven types of posts: text, links and quotes, and it uses curl to send to the server, so if you've removed it, well, that will have to be remedied.

[robg adds: I haven't tested this one.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080123145805535