Convert text links to Devonthink links

I could not locate the exact answer to this question.

My usage case:

  • I annotate PDF files many using the highlighting functions within DT3 to select text + adding my own brief comments in the Details window below
  • I generate a summary of all highlighted content + own comments using the “Summarise Highlights” menu command which generates new Rich Text file

In the summary file the links to the pages are displayed as clickable text links e.g. Page 24 in a blue font which takes me directly to the page in the corresponding PDF file.

My question: is there a way to generate for all links in the highlight summary file the corresponding full x-devonthink-item://… URL instead ? I often copy the summary file to other applications and the link can be lost in the conversion e.g. Page 24 above simply becomes normal text and the link is lost. The full x-devonthink-item URL however will always provide me with a consistent reference to the original document.

The only possibility would be AppleScript.

Which applications actually? Do they support rich text?

Mostly Tinderbox but also sometimes IAWriter. Tinderbox supports RTF and the links are preserved - IAWriter does not,

Even if the links are preserved I sometime copy the link into the Metadata of Tindebox (attributes) which requires access to the devonthink URL written out.

How does one scan the RTF file for links in AppleScript ?

Here’s a simple example:

tell application id "DNtp"
	set theLinks to ""
	repeat with theRecord in (selection as list)
		tell text of theRecord
			repeat with theAttribute in attribute runs
				if exists URL of theAttribute then set text of theAttribute to ((URL of theAttribute) as string)
			end repeat
		end tell
	end repeat
end tell

Ok - I’ll try it out and take it from there. Thanks.

It works in some cases - in others I get the error

error "DEVONthink 3 got an error: Can’t get every text of content id 10419 of database id 3." number -1728 from every text of content id 10419 of database id 3

What files are specifically erroring when you see this?

The script supports only rich text documents.

Yes - I think the problem originated from a Formatted Note which looks a lot like a Rtf file.