
Some of the DEVONthink provided templates are "template packages" (.dtTemplate) and "smart templates" (.templatescriptd). Stored in the ~/Library/Application Support/DEVONthink/Templates.noindex directory, both types of templates provide a great deal of flexibility and power, like allowing for inclusion of language resources. With some creativity and scripting know-how, you can set up everything from commonly used group hierarchies to daily journal entries and much more.
The simpler type of automated templates DEVONthink supports are: template packages. These are folders with the file name extension .dtTemplate that contain one or multiple .lproj folders, one for each supported language. Depending on the system language, you can let DEVONthink import the files in the correct language. If you inspect the contents of a template package, e.g., Classifications > Decimal Filing System.dtTemplate, you will see the project folders and their assets as a great example of this type of template.
The more advanced type of automated templates are smart templates. These are not simple files, but actually AppleScript packages containing script code, and often including related assets that can be inserted into your database. This allows for some very powerful actions like:
Template Packages: To create your own template package, you can duplicate an existing template, Control-click it, choose Show Package Contents and edit the internals as needed. Also note exporting multiple selected files will yield a template package.
Smart Templates: To make your own smart templates, have a look at the prefabricated smart templates. Duplicate a .templatescriptd file, like the "Note" template. Control-click it, and choose Show Package Contents. You can inspect and modify the supporting assets and the main.scpt file to fit your needs.
Placeholders in templates are simple control codes that are replaced by DEVONthink when a template file is imported. These placeholders can be used in your files, including simple templates, or folder names of your templates packages. When used in files, they are typed in the text of DEVONthink-native files; e.g., plain or rich text, Markdown, etc. These can be manually typed or you can Control-click in the text and choose Insert Placeholder. Below is a list of valid placeholders:
Custom Placeholders: One more powerful feature of smart templates is the ability to define custom placeholders, extending the possibilities beyond the list shown here. This allows you to add a custom placeholder in the text of a template, then define the replacement value for that placeholder in the main.scpt. As a great example, check out the use of the custom %project% placeholder in the Project smart template. Notice the use of the placeholder in the enclosed rich text file and the script.
With the internal script of a smart template, there are no special handlers required. However, the internal script must be located in the Contents/Resources/Scripts folder inside the package, and it must remain named main.scpt. Beyond that, you only need valid AppleScript.
If you need to support multiple languages in your templates, it is possible to have the name and/or content change based on the language in which DEVONthink is running. You can add your own definitions in .strings files in the Contents > Resources directory of a template package. Here are the files that can be used:
"en"="My Project"; or "de"="Mein Projekt";..lproj extension, e.g., fr.lproj would contain French strings. Contains localized definitions of words or phrases, e.g., the content in a document created by the template. The syntax defines one word or phrase per line: "Daily Journal"="Tageszeitung";.To add any template to the toolbar, place the template into the folder ~/Library/Application Support/DEVONthink/Templates.noindex/Toolbar. In order for the script to be available for use in the toolbar, you must quit and relaunch DEVONthink. Choose View > Customize Toolbar, drag your template into the toolbar and it's ready for use.