Templates for Rich Text Files

Is there anyway to create a template for the rich text files in Devonthink pro? I’m dealing with a large number of historical documents that I’m taking notes on, and I would like to create a template that has several standard pieces of information, like date, author, subject, administration, etc. That way I could search and sort these documents based on the template information.

Thanks for any suggestions.

A quick search for “template” in the DTP help file revealed this:

In DEVONthink Pro Office you can create new documents by first marking some text in a rich text document and making it a link. When you then click this link, DEVONthink Pro Office creates the new document using a template you can define in the preferences panel, Editing tab. In this template, you can use the tags below to automatically insert the name of the link, the current date or other information. [Read more…]

%@: Name of link
%%: A ‘%’ character
%a: Abbreviated weekday name
%A: Full weekday name
%b: Abbreviated month name
%B: Full month name
%c: Shorthand for ‘g%X %x,’ the locale format for date and time
%d: Day of the month as a decimal number (01-31)
%e: Same as %d, but does not print the leading 0 for days 1 through 9
%F: Milliseconds as a decimal number (000-999)
%H: Hour based on a 24-hour clock as a decimal number (00-23)
%I: Hour based on a 12-hour clock as a decimal number (01-12)
%j: Day of the year as a decimal number (001-366)
%m: Month as a decimal number (01-12)
%M: Minute as a decimal number (00-59)
%p: AM/PM designation for the locale
%S: Second as a decimal number (00-59)
%w: Weekday as a decimal number (0-6), where Sunday is 0
%x: Date using the date representation for the locale, including the time zone
%X: Time using the time representation for the locale
%y: Year without century (00-99)
%Y: Year with century (such as 1990)
%Z: Time zone name (such as Pacific Daylight Time)
%z: Time zone offset in hours and minutes from GMT (HHMM)

:wink:

@ssemmler: I already use the Wiki-link template trick to create new documents based on a (unfortunatly single) template.

But I would second the ‘thegrossz’ idea: just be allowed to perform something like “Data > New Rich text With Template” to create a new document based on the template referenced into the Preference

As usual, there are workaround approaches.

The following approach works especially well if you wish to have multiple “template” setups.

Create a new rich text document and enter any text you choose, e.g. Author:; Title:; Publication Date"; etc… Save it. In the Info panel, use the option to lock this document so that it cannot be changed.

To use it, duplicate it and unlock the copy.

tell application "DEVONthink Pro"
	set theTemplateName to "Basic Template"
	set theTemplateItems to search theTemplateName comparison exact within titles
	set theTemplate to the rich text of item 1 of theTemplateItems
	set theSelection to the selected text of think window 1
	set theNewItem to create record with {name:theSelection, type:rtf, rich text:theTemplate}
	open window for record theNewItem
end tell

How about this:
Create a script, paste this code in. Make as many as you want for however many templates you’ll have, organize them however you want, just change the value of theTemplateName.
Create a template named with the value of theTemplateName. Put it somewhere. Make sure it’s a unique name, otherwise this script will just use the first one that pops up.
In the file that you’re currently editing, write something like “cow”, select it, run the AppleScript, and a window will pop up with a new document called “cow” in the root directory, and it’ll contain the template file’s contents.

Hope that helps.

Hi – many thanks for this, it looks very useful. But I did try it, and while the script produces a new document which has the textual information from the template in it, the table in the template is not being copied.

Any ideas?

Thanks in advance, Andreas

Hmm. Perhaps something in the way OS X or DTP handles rich text?

Okay, let’s try

tell application "DEVONthink Pro"
	set theTemplateName to "Basic Template"
	set theTemplateItems to search theTemplateName comparison exact within titles
	set theTemplate to item 1 of theTemplateItems
	set theSelection to the selected text of think window 1
	set theLocation to the location of the content record of think window 1
	set theNewItem to (duplicate record theTemplate to theLocation)
	set the name of theNewItem to theSelection
	open window for record theNewItem
end tell

For some reason, I’ve never been able to get DTP to handle database paths right. In this case, even though I think I’ve gotten the syntax right, the script just throws the new file in the root path.

Anyway, what this does is duplicate the template and then rename it and open it in a new window. I should’ve just done this to begin with, I guess :slight_smile:

Thanks. The formatting is now OK, but the new record is locked (as is the template). Any idea how to get rid of that? Sorry :confused:

Andreas

Update: I found the answer myself with set locking to false; however, the record still lands in the home directory rather than the groups it was launched from…

I don’t understand that. I’m going to do some experimentation and try to figure out what I’ve been doing wrong with database paths.


tell application "DEVONthink Pro"
	set theSelection to the selection
	set theItem to the first item of theSelection
	set thePath to the location of theItem
	display dialog thePath
	duplicate record theItem to thePath
end tell

This dumps the newly-created record in the root directory, even though thePath contains a perfectly legal location definition. I don’t understand why. It seems perfectly straightforward to me – it just doesn’t work.

Bug? :-/

Edit: Disregard, I am an idiot. But see below.

Okay, I realized that location is worthless and should be parent, but nevertheless, the variations I’ve tried with parent of and id of the parent of and so forth have not worked. Even move/duplicate/replicate record theNewItem to the parent of theItem will not work.

Has anyone else had any success with the duplicate/replicate/move verbs in AppleScript?