copy regex match into spotlight comment

I’ve devised a little script —my first Applescript— to find a range of digits within curly braces and copy it into the spotlight comment field in DT Pro (the page range in curly braces with possible text before and after is part of my DT Pro — Scrivener — Mellel — Bookends workflow). At present, it requires that something be present in think window 1 to work. I would like to automate this script such that I can select more than one file at a time and run it on all of them, but I can’t figure out how to do that. (Applescript’s text selection options are woefully inadequate, thus far).

I’ve copied the script below — it include certain features that I think will need to be present in order to run it on multiple files, but are not necessary for it to run in its current form. I pulled a lot of material out of the “Set comments to tags” script included with DT Pro. Can any Applescript magicians help me out? Thank you!

tell application id "com.devon-technologies.thinkpro2"
		set these_items to the selection
		if these_items is {} then error "Please select some files."
		repeat with this_item in these_items
			set allText to text of think window 1 as string
			set curlyBraces to find text "\\{.+" in allText with regexp and string result
			set theText to find text "[0-9]+\\-?[0-9]*" in curlyBraces with regexp and string result
			if the comment of this_item is not "" then
				set oldComment to the comment of this_item
				set the comment of this_item to theText & " " & oldComment
			end if
			if the comment of this_item is "" then
				set the comment of this_item to theText
			end if
		end repeat
	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

I didn’t try your script, but why can’t you say?

set allText to text of this_item

HTH, Charles

Well, I wondered that myself, but when I tried it, DT Pro threw an error: “Can’t get every text of content id 177476 of database id 2”.

Sorry, I could have been a little less careless. Try “plain text”:

set allText to plain text of this_item

Best, Charles

Magic! Thank you!!!