Script for annotations of multiple files in separate groups

I’m currently setting up a DT database and placing PDF files of publications in separate groups. There is a great script I’m using for that (it was created by by cgrunenberg in response to SteveJT’s post: Group each item script). Anyway, I’d like to have a blank annotation RTF associated with each PDF. I’ve tried to create annotation RTFs by selecting multiple files (first by selecting multiple groups) and then running the Annotation script. I had hoped that this would result in an annotated file being created alongside each PDF within each group but alas it didn’t work.

Is such a script feasible? If so, I would be grateful if a skilled Dthinker would write and post it.

Thank you!

This script should create the desired empty annotations for all selected documents:


tell application "DEVONthink Pro"
	set theSelection to the selection
	repeat with theRecord in theSelection
		if type of theRecord is not bookmark and type of theRecord is not feed then
			set theURL to URL of theRecord
			if theURL does not start with "x-devonthink-item:" then
				set theParents to parents of theRecord
				set theAnnotation to create record with {name:(name of theRecord) & " Annotation", type:rtf, content:""} in (item 1 of theParents)
				repeat with i from 2 to (count of theParents)
					replicate record theRecord to item 1 of theParents
				end repeat
				
				if theURL is not "" then
					set theComment to comment of theRecord
					if theComment is not "" then set theComment to theComment & return
					set theComment to theComment & "Original URL" & ": " & theURL
					set comment of theRecord to theComment
				end if
				
				set URL of theAnnotation to reference URL of theRecord
				set URL of theRecord to reference URL of theAnnotation
			end if
		end if
	end repeat
end tell