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

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

This script is deprecated – the Create Table of Contents command, added in newer versions of DEVONthink, does essentially the same thing. There are also UTF issues here that I have no interest in fixing. Please IGNORE this thread.

(*
	v1.20131108.korm
	Put an index of the selected documents into a new RTF file in the current group
*)

-- if a label is desired for the index file change this property to an integer from 1 to 7, corresponding to the configured label in DEVONthink
property p_label : 0

-- if you wish to be prompted for the destination for the index file, change this property to true
property ask_destination : false

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" as rich text)
		
		set defaultIndex to "01 Contents Index " & (the name of the current group)
		
		set documentName to text returned of (display dialog "Please enter the new file name	" default answer defaultIndex with title "Name of File?")
		
		if ask_destination then
			create record with {name:documentName, rich text:o_RTFLink, label:p_label, type:rtf} in display group selector
		else
			create record with {name:documentName, rich text:o_RTFLink, label:p_label, type:rtf} in the current group
		end if
		
	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

There are seven labels possible in DEVONthink (DEVONthink > Preferences > Labels). Scripts can add labels. In the script posted above change the property p_labelto an integer from 1 to 7, corresponding the the 1st through 7th labels in the Labels configuration. Set the property to some other integer (prefer zero) if no label is desired. The default is no label.

Thanks Korm. A couple of queries as I am not familiar with writing scripts!

  1. When I run the script as is I get an error message:Error.jpg how do I deal with this?

  2. With regard to Labels the numer is 2. So where exactly in the script do I change? Presumably it is somewhere here:

Thanks for your help and time.
Regards Andrew

I’m afraid you have somehow mangled the code when you copied it. I can’t help fix what I can’t see, because I can’t see what you pasted into AppleScript Editor.

Okay. :blush: Here is what I posted:

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" as rich text)
	
	set defaultIndex to "01 Contents Index " & (the name of the current group)
	
	set documentName to text returned of (display dialog "Please enter the new file name   " default answer defaultIndex with title "Name of File?")
	
	if ask_destination then
		create record with {name:documentName, rich text:o_RTFLink, label:p_label, type:rtf} in display group selector
	else
		create record with {name:documentName, rich text:o_RTFLink, label:p_label, type:rtf} in the current group
	end if
	
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

Look, you need to copy all of the code that’s posted for these scripts, not some of it. :imp: :stuck_out_tongue:

Please, go back to the top posting in this thread. Look for this:

Press “Select All”. Everything will be in blue. Press command-c (Copy). Go to a new document in AppleScript Editor. Press command-v (Paste). Compile. Save. Run.

Your label question was answered twice, above – in the comments in the code and in my second posting.

Absolutely wonderful :smiley: I have got it to run just as I wanted. Many thanks for doing this & your patience with me & appologies for my ignorance. Very grateful thanks, Andrew

'k :smiley:

Many thanks Korm - just tried it, works like a charm. Possibilities are almost endless! :slight_smile: