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"
try
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