since i’m not great at applescript, and i’m not 100% sure of your environment, i think the easiest thing to do is to post what i have so you can see what i did.
first off, i started with the bundled template “Project”. It has a file/folder structure that it uses to populate a new project in DTPO. i made a copy, and modified the structure to include only 2 files in the provided structure: the ‘about this project’ RTF file, and an empty task RTF (that i modified). i wanted to fire this template off and have a pre-populated structure get dropped into a dedicated group, and replace various placeholders to set text within the 2 RTF files.
the template script, main.scpt, was what i modified to be this:
-- Smart template adding a localized project template to the current group
-- Written by Eric Böhnisch-Volkmann, modified by Christian Grunenberg
-- © 2009 DEVONtechnologies, LLC
-- Default non-localized project name, also used to identify the resources
property pTemplateName : "New Project"
property pInsertNameHere : "First Last"
property pInsertEmailHere : "me@email.com"
property pInsertDeptHere : "My Department"
property pInsertPhoneHere : "(800) 555-2368"
property pAboutDocument : "About this project"
property pBlackColor : {0, 0, 0} -- RTF text color
-- Import helper library
tell application "Finder" to set pathToAdditions to ((path to application id "com.devon-technologies.thinkpro2" as string) & "Contents:Resources:Template Script Additions.scpt") as alias
set helperLibrary to load script pathToAdditions
set startDate to do shell script "date '+%F'"
try
-- We're later working in DEVONthink, we need to cache localized strings while still in our realm
set theProjectName to localized string pTemplateName
set theUserName to my helperLibrary's localizedString(pInsertNameHere)
set theUserEmail to my helperLibrary's localizedString(pInsertEmailHere)
set theUserDept to my helperLibrary's localizedString(pInsertDeptHere)
set theUserPhone to my helperLibrary's localizedString(pInsertPhoneHere)
tell application id "com.devon-technologies.thinkpro2"
-- Let the user change the project name
set theProjectName to display name editor my helperLibrary's localizedString(pTemplateName) default answer theProjectName info (my helperLibrary's localizedString("Please enter a name for this project") & ":") as string
set thePlaceholders to {|%email%|:{|URL|:"mailto:" & theUserEmail, |name|:theUserEmail}, |%dept%|:theUserDept, |%phone%|:theUserPhone, |%project%|:theProjectName, |%start%|:startDate}
-- Import the predefined structure
set theDatabase to open database "/Users/user/Library/Application Support/DEVONthink Pro 2/Databases/To-Do_List.dtBase2"
set theGroup to create location "/Projects/Active" in theDatabase
set theTemplateFiles to helperLibrary's pathToLocalizedResources() & my helperLibrary's localizedString(pTemplateName)
set theRecord to import theTemplateFiles placeholders thePlaceholders to theGroup
set the name of theRecord to theProjectName -- Rename to user-defined project name
end tell
on error errMsg number errNum
if errNum ≠ -128 then display alert (localized string "An error occured when creating the new project structure") message errMsg as warning
end try
the relevant bits are the shell script to get today’s date in a usable format (which is tough using applescript), and the ‘tell’ block within the ‘try’ block. this sets the necessary database to the DB i want to always use (“To-Do List.dtBase2”) by setting the filesystem path. it then populates a variable to contain the path within the DB to the required group tree ("/Projects/Active"). then it imports the structure, replacing placeholders with the localized variable set at the beginning, and renames the new project (which is a group) to the project name i provide in the prompt.
the parts that got me were setting the DB path (which works whether the DB is open or not), and the group path, which doesn’t create a new path, but uses what is there already (if it exists).