I may be missing something obvious, but how do you create a new RTF record and include a clickable link in the body of a note?
set theRTFContents to “blah blah”& linefeed & “x-devonthink-item://1234”
set theNewRecord to create record with theRTFContents
So in this example, the x-devonthink link should be clickable. Bonus points if I can create a link with the text being something other than the url itself.
Any pointers would be much appreciated.
The only thing I can find on the forum is this old thread, but the solution doesn’t seem to work now.
RTF files are not that good a choice for scripting URLs. Possible? Yes. Simple? Not so much.
At a minimum, you can put the link into the contents but make sure DEVONthink’s Preferences > Editing > Smark Links is checked.
This is a simple core example, with an RTF file displayed in the window…
tell application id "DNtp"
tell text of think window 1
make new paragraph at end with data (return & "http://google.com” & return)
end tell
end tell
Thanks for the pointer. It’s not quite what I was looking for as I’m creating a new record, rather than having an existing one selected, but that suggests I need to rethink what I’m trying to do.
No problem.
While I’m still not a big advocate of RTF for this kind of thing, here’s a little snippet that may give you something to ponder…
tell application id "DNtp"
set newDoc to create record with {name:"NewDoc", type:rtf, content:""} in current group
set selection of think window 1 to {newDoc}
tell text of think window 1 to make new paragraph at end with data "x-devonthink-item://746D55BE-1764-41E5-A233-5D330E26166E"
end tell
This requires a view with a display, ie. not Icon or List views.
Cheers!
Generally selection is to be read, but it can be used this way too. However, it’s often misused (or misunderstood), so when you’re automating, always stop and carefully consider if a selection actually needs to be made. It’s more rare that it does.
Cheers!