Add URL to Text

Just wondering if anybody has a script to take the URL from an item in DEVONthink and add it to the text within the item.

To clarify, I have a few folders with about 300 text documents each. Each document has the URL field filled out, I am hoping to copy the URL from the URL field and append it to the text within the respective document.

Or if there is a better way to do this without manually going through each one, I would appreciate it.

Here’s a simple example but it supports only plain/rich text:


-- Insert URL in text. Requires split, column or 3-pane view.

tell application id "DNtp"
	set theWindow to think window 1
	copy the selection of theWindow to theSelection
	repeat with theRecord in theSelection
		if type of theRecord is rtf or type of theRecord is rtfd or type of theRecord is txt then
			set theURL to URL of theRecord
			if theURL is not "" then
				set the selection of theWindow to {theRecord}
				tell text of theWindow
					make new paragraph with data (theURL & return & return) at beginning
				end tell
				tell theWindow to save without asking
			end if
		end if
	end repeat
end tell

That is working great with RTF files, but not working with txt files, as most of my files are txt do you have any ideas what might be going wrong?

I thought it might have been the “make new paragraph” but changing that to “make new line” also didn’t work.

I would appreciate any ideas.

I’m curious what you’re using the URL for in a plain text document, as the link wouldn’t be active.
And is this data appended or prepended?

I’m appending the URL to the file, I was able to change beginning to end in the script to accomplish that.

I need the URL in the document for 2 reasons, often times I write notes about the page in the text document, then need to send the text to someone, and I need to include the URL, having it already in the document would save time.

The other reason is because I experienced an issue (user error) on my iPhone where I accidentally cleared the URL from the info panel and had no way of getting it back on my iPhone. I had to go to my Mac and grab it from a backup. If it was in the document I would be able to replace it immediately on my iPhone.

This script should support plain texts too:


tell application id "DNtp"
	set theWindow to think window 1
	copy the selection of theWindow to theSelection
	repeat with theRecord in theSelection
		if type of theRecord is rtf or type of theRecord is rtfd or ((type of theRecord) as string) is "text" then
			set theURL to URL of theRecord
			if theURL is not "" then
				set the selection of theWindow to {theRecord}
				tell text of theWindow
					make new paragraph with data (theURL & return & return) at beginning
				end tell
				tell theWindow to save without asking
			end if
		end if
	end repeat
end tell