Netnewswire and DevonThinkPro - import flagged to DTP

Hello there!

Is there a way/script through which I can import my flagged Netnewswire items to my DT database? I think this would be extremely useful to the users of both applications

You might have a look at the script “~/Library/Scripts/Applications/NetNewsWire/Add news to DEVONthink.scpt”.

Yes! I’ve seen it and I’ve been using it for quite some time now. I was just wondering if there was a script or a modification of the script previously mentioned so as to import my flagged items from the Nnw to DTP.

This would help as it would it enhance my productivity, i.e read the news from NNW, flag the most important or interesting news while reading them, and then import all my flagged news into DTP so as to have them available / archived.

I’ve been increasingly wanting a more efficient way to add batches of news items (not necessarily flagged) to DTP from NNW. NNW 3.0 supports Clippings folders and being able to archive those to DTP would be convenient.

I’ll let you know if I find a solution or eventually enough have enough scripting skill to write something myself.

Here’s a simple example adding all flagged items of the currently selected subscription to DEVONthink Pro:


tell application "NetNewsWire"
	try
		if exists selectedSubscription then
			set this_subscription to selectedSubscription
			set these_headlines to headlines of this_subscription
			repeat with this_headline in these_headlines
				if this_headline is isFlagged then
					set h_title to title of this_headline
					set h_note to description of this_headline
					if exists date published of this_headline then
						set h_when to date published of this_headline
					else
						set h_when to date arrived of this_headline
					end if
					set h_URL to URL of this_headline
					set h_note to "<html><body><p><a href=\"" & h_URL & "\"><bold>" & h_title & "</bold></a></p><small>" & h_note & "</small></body></html>"
					tell application "DEVONthink Pro" to create record with {name:h_title, type:html, date:h_when, URL:h_URL, source:h_note}
				end if
			end repeat
		else
			error "No subscription is selected."
		end if
	on error error_message number error_number
		if the error_number is not -128 then
			try
				display alert "NetNewsWire" message error_message as warning
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end tell

lovely!

thanx for your reply!

Nice… thanks!

How hard would it be make this and the original Add news to DEVONthink script more tolerant of items that trigger “The variable h_note is not defined” errors? The Mark/Space Users feed is an example with that problem.

I didn’t check this but this revision should handle this by adding just a bookmark if the currently selected item has no content/description:


tell application "NetNewsWire"
	try
		if exists selectedHeadline then
			set this_headline to selectedHeadline
			set h_title to title of this_headline
			set h_URL to URL of this_headline
			if exists date published of this_headline then
				set h_when to date published of this_headline
			else
				set h_when to date arrived of this_headline
			end if
			if exists description of this_headline then
				set h_note to description of this_headline
				set h_note to "<html><body><p><a href=\"" & h_URL & "\"><bold>" & h_title & "</bold></a></p><small>" & h_note & "</small></body></html>"
				tell application "DEVONthink Pro" to create record with {name:h_title, type:html, date:h_when, URL:h_URL, source:h_note}
			else
				tell application "DEVONthink Pro" to create record with {name:h_title, type:link, date:h_when, URL:h_URL}
			end if
		else
			error "No headline is selected."
		end if
	on error error_message number error_number
		if the error_number is not -128 then
			try
				display alert "NetNewsWire" message error_message as warning
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end tell

That’s helpful, thanks. This revision to your revision also tries to use the item summary if the description is missing:

tell application "NetNewsWire"
	try
		if exists selectedHeadline then
			set this_headline to selectedHeadline
			set h_title to title of this_headline
			set h_URL to URL of this_headline
			if exists date published of this_headline then
				set h_when to date published of this_headline
			else
				set h_when to date arrived of this_headline
			end if
			if exists description of this_headline then
				set h_note to description of this_headline
			else if exists summary of this_headline then
				set h_note to summary of this_headline
			else
				tell application "DEVONthink Pro" to create record with {name:h_title, type:link, date:h_when, URL:h_URL}
			end if
			set h_note to "<html><body><p><a href=\"" & h_URL & "\"><bold>" & h_title & "</bold></a></p><small>" & h_note & "</small></body></html>"
			tell application "DEVONthink Pro" to create record with {name:h_title, type:html, date:h_when, URL:h_URL, source:h_note}
		else
			error "No headline is selected."
		end if
	on error error_message number error_number
		if the error_number is not -128 then
			try
				display alert "NetNewsWire" message error_message as warning
			on error number error_number
				if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
			end try
		end if
	end try
end tell

Logic flow could be improved and integrated with the flagged items version. Successfully tested with several feed items containing summary text without corresponding description text. That occurs more frequently than I realized and causes undefined variable errors in bundled NNW scripts. Not sure what’s (in)valid since I’m unfamiliar with RSS/Atom specs.