Templates

Hi

 This appleScript used to produce a labeled rich text template that I could fill in and save. However, it now doesn't seem to work consistently with DevonThink Pro 2. Instead of the rich text Notes template, I get a  - somewhat a random - filled in version of something that I created at a previous time. It is almost if the script is failing and DevonThink is grabbing something at random.

tell application “DEVONthink Pro”
set theTemplateName to “Notes”
set theTemplateItems to search theTemplateName comparison no
case within titles
set theTemplate to the rich text of item 1 of theTemplateItems
set theDate to the current date
set d to the (day of theDate) as text
set m to the (month of theDate) as text
set y to the (year of theDate) as text
set ts to the (time string of theDate) as text
set theSelection to (m & " " & d & " ," & y & " " & ts)
set theNewItem to create record with {name:theSelection, type:rtf,
rich text:theTemplate}
open window for record theNewItem
end tell

The search command is probably returning multiple items now and therefore the first item might not be always the same or the intended one. I’d suggest to reference the template in another way, e.g. have a look at the commands “get record at” or “get record with UUID”.

BTW, the upcoming beta will improve the support for templates a lot, both with and without scripting.

Thanks. You are quite right as that is exactly what is happening. Somehow I had allowed records with somewhat the same title to accumulate and as time passed the one I used for a template was no longer first.