OK, so I can see a lot of people seem to have this problem, but I’m still struggling, so I’ll have to ask.
I create a rich text document with the following placeholders:
%recordName%
%recordCreationShortDate%
I save this Rich text document as a template, since I understand that placeholders don’t work on already created documents. This isn’t ideal but ok, no problem.
3, However, when I create a new Rich Text Document using the template, all I get is the text formatted as above, neither the record name or creation date get populated with anything.
I realise you’ve posted this as some kind of ‘gotcha’, but I read this article and it didn’t make sense to me, hence me asking a more basic question here on the forum.
For example ‘you’ll need a script to accomplish this, because there are some more steps involved in order to accomplish what you want.’
I don’t think I’ve ever been put off an app I like by an obnoxious user-base quite so much in a long time.
Yes, this situation requires a bit of scripting as the record doesn’t have a name when before it’s created. The placeholder doesn’t operate post-creation.
Here is a simple example based on the thread referred to above…
property templateFile : "~/Library/Application Support/DEVONthink 3/Templates.noindex/template with custom placeholder.txt"
--This is the template. The name here is unrelated to the created document's name since it's being specified in theName below *)
tell application id "DNtp"
set theName to "new file"
-- This is the name applied to the new document created from the template
import templateFile name theName placeholders {|%recordName%|:theName} to incoming group
-- The `%recordName%` placeholder is replaced in the document's contents
end tell
Please forgive a slightly off-topic question regarding:
I occasionally see the “| … |” notation in DT AppleScripts but I don’t entirely understand it. As you might imagine, results of web searches for “applescript |” aren’t too helpful.
Other than “vertical bar” or “pipe,” what is the “|” operator called in this scenario, and what is the sequence “| … |” called?
In this script, the purpose seems to reference the occurrence of the string literal “%recordName%” in the contents of templateFile, but I have seen it in other contexts that extract data from an item’s metadata, as in:
set theSubject to |kMDItemSubject| of theMD
In the post:
In this scenario, are “|” and “| … |” called the same thing as in the “|%recordName%|” scenario?
It seems that the target of these constructs is text/string. Are there other uses of these constructs?
That has nothing to do with DT, it’s just a notation of AS. AFAIK (and I may be wrong because I don’t really know this language), the |…| notation is used to refer to fields (attributes, properties, whatever they are called) of a record.
So, learning about AppleScript’s records might tell you all the gory details.
I’m not sure what “target” means. But I am sure that the post you’re quoting is so old (referring to DT version 2) that you should not refer to it. In this case, we’re talking about FOURTEEN years.
As things stand now, you don’t need the bars in this situation (anymore?).
This syntax is only required if the key (used to access a value in a list of key-value-pairs or records/dictionaries) is also a part of the script suite syntax. In this case…
set theSubject to |kMDItemSubject| of theMD
…it’s therefore optional and set theSubject to kMDItemSubject of theMD would also work. But always using |...| ensures that you don’t have to worry about such conflicts.