Making clickable links

Probably an old question, but:

When I type a URL or DevonThink item link (x-devonthink-item://…) into a rich text document, or use a script to do the same, it appears only as text.

However, if I paste the same link into the same document, it appears as a clickable link.

How do I tell a script to make such links clickable?

Thanks, and sorry if this has already been covered.

Thanks for the answers below.

This doesn’t really tell us much about how you’d like to make/use the link.

To make a link you need two pieces of data:

  1. the selection that you’ll click on
  2. the target of the click: the hyperlink

Where are these two bits coming from? clipboard? selection?

With a bit more detail, perhaps someone could help.

Anyway, it should be something like this:

tell application "DEVONthink Pro"
	set URL of attribute run of selected text of tab 1 of think window 1 to "x-devonthink-item://3F2EFA3E-4139-4E5F-88E1-972DEDB6E1F2"
end tell

Best wishes, Charles

There is also a simple solution that does not involve scripting. If you right-click in the body of the target document and select ‘Substitutions>Smart Links’, all URLs will be converted to a link after typing them (you need to type the spacebar after entering the URL so that the OS knows to convert the text to a link). You only need to do this once per document-all subsequent URLs will be converted automatically.

While we’re on the subject, you can also say something like:

tell application "DEVONthink Pro"
	URL of every attribute run of rich text of content id 591132 of database id 6
end tell

Which will return a list of all the links in a document.

So if you want to “screen scrape” an HTML file, you can easily get all the links of a page by consulting its rich text representation.

Charles

Well, here’s an example of what I want to do. This script records the url or item link of each open tab in a window in a rich-text document: ```
tell application “DEVONthink Pro”

set theWindow to front window
set theText to ""

repeat with theTab in (get tabs of theWindow)
	if theTab's URL is not "" then
		set theLink to theTab's URL
		set theSource to theTab's source
		set theName to get title of the theSource
	else
		set theAddress to get uuid of content record of theTab
		set theLink to "x-devonthink-item://" & theAddress
		set theName to name of content record of theTab
		
	end if
	
	set the theText to theText & return & theName & return & theLink & return
	
end repeat

create record with {name:"Tab links", type:rtf, rich text:theText} in incoming group

end tell

Looking at your code, you are trying to create the link on a plain text string. Strings aren’t rich text, so you’re lost.

I would suggest creating an RTF file with the name of each record and return; then go back and set the URL of the attribute run of each paragraph to the URL or UUID depending on what you want/have.

HTH, Charles