Create or modify placeholders?

When creating templates, DT allows me to include certain “placeholders.” For example, placing “%time%” in the template will record the actual time when the file is created. (See p. 144 of the 2.3 user manual for more examples.)

My question is whether there is any way to create my own placeholder or modify one of the existing ones. I would like to create one that inserts a random string of numbers and values at the end of a document, which would be used as a sort of unique ID for the document.

If it is not possible to create a random string, then would it be possible to modify an already-existing placeholder? At present, I use the following to approximate a unique ID: “%year%%month%%day%%time%”. This works pretty well, since I am usually not creating more than one document in the same second of the same day of the same month… For all intents and purposes, it is a unique identifier. The only problem with it is that the %time% placeholder includes colons (i.e. “:”) to distinguish hours from minutes and seconds. While DTP does not seem bothered by colons, I have found that Spotlight will not reliably search strings that have colons in them–at least Spotlight can’t find DTP documents when searching by the unique string if the string as colons in it. (I don’t understand why.) In any case, if I could modify the placeholder to exclude the colons, then that would satisfy my larger goal of being able to place a searchable unique identifier in each file I create from a template.

Any thoughts?

1 Like

You can create your own placeholders, and to use them you need to make a template package (e.g., .templatescriptd), and modify the script located inside that template package at Contents:Resources:Scripts:main.scpt.

Check the DEVONthink script dictionary for the import command. You’ll use the placeholders parameter, for example in this code from the “Notation” template:

import theFile placeholders {|%theDate%|:theDateStr, |%theTime%|:theTimeStr} to current group

Those placeholders in that snippet ("%theDate%" and “%theTime%”) can be customized in the script. You also need to adjust the .rtf file which serves as the model for the template. For example, look at Contents:Recources:description.rtfd in the Notation.templatescriptd package to see how it works.

It’s all actually a lot less work than it appears. Merely copy a template - name it to what you want, retaining the .templatescriptd extension - modify the .rtf file inside the template package - and modify the script inside the package.

Thanks much for your response. I’m afraid I’ll need to think about this a bit, though. I’m not an applescript aficionado, so maybe that is a prerequisite. With some playing around, I might be able to cobble something together.

I was trying to follow your example, but I’m not sure what you mean by the “Notation” template. I have an Annotation template and a Note template, but not a Notations template. Neither of the scripts within the templates I looked at had the command you quoted.

As often happens with me, it is possible that my interests are beyond my capacity to address them. Thanks again.

The Notation template might be something I’ve had hanging around for a while - but any template can be used as an example. You’re right - it takes some scripting know-how — but not much :confused:

I would like exactly what cdc is asking for, but am clueless when it comes to scripting. (Just spent an hour looking into it, but that didn’t do it.)

Anyone out there who would be willing to put such a template together?