Put RTF link(s) to selected documents on the clipboard

Sometimes I want to put a reference to several documents that are stored in my databases into another document. This script helps with that. I select several documents or groups, run the script, and it puts RTF link(s) to all of the selected documents onto the clipboard. The script works with documents or groups, and it works with contiguous or discontiguous selections - but for now it will not mix documents and groups in the same selection.

(*
	Put rich text link(s) to the selected records (or groups) in DEVONthink onto the cliboard
	For pasting to another document or rich-text aware location.
	
	v1.20131106.korm
*)

tell application id "com.devon-technologies.thinkpro2"
	try
		set theSelection to selection
		if theSelection is {} then error "Select an item, please"
		
		set o_HTML to ""
		
		repeat with thisItem in theSelection
			
			set thisName to the name of thisItem
			set thisURL to the reference URL of thisItem
			
			set o_HTML to o_HTML & quoted form of ("<font face=\"helvetica\"><a href=\"" & thisURL & "\">" & thisName & "</a></font> </br>")
			
		end repeat
		
		set o_RTFLink to (do shell script "echo " & o_HTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf" as rich text)
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
	
end tell

Here’s what happens: I have this selection in a database:

and I run the script, which puts this on the clipboard:

The underscored text are clickable links that, in an RTF-compatible document, will open the linked documents in DEVONthink

This script is very useful to me, thanks Korm :smiley: I can now easily create a Rich Text index of what is in a Group, marvellous for my Genealogical work. Cheers.

:stuck_out_tongue:

Having used this now a few tmes I find that I would like to extend this script if possible. This is my workflow after running this script:

  1. Open a new RTF document
  2. Label that document with a specific label
  3. Name that RTF with the text “01 Contents Index ” (including the space)
  4. Add the name of the Group to the name of the RTF document
  5. Paste from the clipboard into the RTF

I know this is quite an ask but if it is possible I am sure Korm or someone else would be able to do it :wink:

Depends on time. Questions in blue

  1. Open a new RTF document – An existing one or a new one?

  2. Label that document with a specific label – What is “a specific label”?

  3. Name that RTF with the text “01 Contents Index ” (including the space) – 'K

  4. Add the name of the Group to the name of the RTF document – The name of what group?

  5. Paste from the clipboard into the RTF – At the top?

Do you use TextExpander and/or Keyboard Maestro? With KM this would be a piece of cake for you to build and customize. Just saying.

Q.1) A new one.

Q.2) The label will always be green, which I have allocated to this type of document.

Q.3) I do not understand your blue – ‘K

Q.4) The name of the Group that the new RTF is located in, e.g. if I am creating a new RTF in a Group entitled "Allsop, Andrew” then “Allsop, Andrew” should be appended to the name of the RTF. The resultant name would then be "01 Contents Index Allsop, Andrew”.

Q.5) In the body of the RTF which, as it is a new one, will be blank.

I do not use KM or Text Expander, have LaunchBar which I like. Had a look at KM but the cost seemed prohibitive for what I would use it but might be wrong in that!!! Hope this is clear. Thanks for looking at it.

See Make an Index Document (RTF) for a Selection of Documents