Posting to WordPress from NetNewsWire

Earlier this evening, I found an Applescript to post links to my account from NNW here.

I like it, because it gets me one step closer to ditching Safari in favor of NNW (I have nothing against Safari, nor do I love NNW, but I really enjoy having he integrated feed reader and browser).

The things that keep me attached to Safari are:

  1. I really like being able to hit Cmd-# and launch a bookmark from the bookmark bar. I use this mostly for launching bookmarklets. I have bookmarklets for posting to, posting to this blog, doing a Technorati cosmos search, doing a Google related pages search, etc. In order for me to switch, I need to have the ability to do script these same tasks (the command shortcuts would just be wonderful).
  2. NNW is still a bit rough around the edges. This is mostly because I’m using the beta versions of NNW 2. I’m sure this will get better.
  3. NNW doesn’t have auto-complete and history
  4. There is no reason 4

So, in attempting to make this happen, I tried this evening to replace my WordPress bookmarklet (which I use in Javascript) with an Applescript one in NNW. I got everything except for a way to find the excerpt from the page. For various reasons I’m not sure how to do this (having the feed reader and browser complicates this). I’m open to suggestions. Here’s what I’ve got:

--adapted from:

set blogUrl to ""

tell application "NetNewsWire"
	set i to index of selected tab + 1
	set allurls to URLs of tabs
	set myurl to item i of allurls
	set alltitles to titles of tabs
	set temptitle to item i of alltitles
end tell
set mytitle to encode_text(temptitle, true, true)
tell application "NetNewsWire"
	--set toopen to "" & myurl & "&title=" & mytitle
	set excerpt to ""
	set toopen to blogUrl & "wp-admin/bookmarklet.php?text=" & excerpt & "&popupurl=" & myurl & "&popuptitle=" & mytitle
	open URL in new tab with toopen
end tell

--this function taken from:
on encode_text(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%>< {}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:<>"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to (the encoded_text & this_char)
			set the encoded_text to (the encoded_text & encode_char(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encode_text

on encode_char(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encode_char

Comments are closed.