Home | Appendix

Quick links: |  | Template packages Smart templates Creating Templates Template Placeholders Terminology Template Localization Toolbar Templates

|  |  | Smart Templates

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. Template packages 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. Smart templates 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: The script can add information to the built-in template, e.g., the current date and time or data from the web. The script can act intelligently on data on the clipboard: If it's a simple text, it adds the text; if it's a URL, it adds it to a different area of the document and makes it clickable. The script can check if a certain application is installed, e.g., OpenOffice, before adding a document. Creating Templates 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. Template Placeholders 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: %time%: The current time %date%: The current date %shortDate%: The current date in short format %longDate%: The current date in long format %monthname%: The month name of the current date %weekday%: The week day name of the current date %day%: The day number of the current date %month%: The month number of the current date %year%: The year number of the current date %author%: The Author set in the Editing > General settings %username%: The user's name %fullUsername%: The user's full name %organization%: The user's organization from Contacts %emailAddress%: The user's email addresses from Contacts %host%: The host name %databaseName%: The database name %databasePath%: The database's path %groupName%: The name of the parent group %topGroupName%: The name of the top group %clipboard%: The clipboard contents as plain text %styledClipboard%: The clipboard contents as rich text %clipboardLink%: The clipboard contents as a clickable rich text link if the clipboard contains a valid URL
Note: There are more placeholders from the context menu than can be used in a template. For example, the placeholder `%record_locality%` relates to an existing record, so this placeholder will not be used when creating a file from a template.
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. Terminology 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. Template Localization 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: LocalizedNames.strings: Contains definitions of the localized name of the item created by the template. The syntax defines one name per line: `"en"="My Project";` or `"de"="Mein Projekt";`. Localizable.strings: This file must be contained in a subdirectory of the Resources folder, named with the country code and `.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";`. Toolbar Templates 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.