Once again, I managed to spend a day ignoring my corporate tax and business ethics assignments and make a handy (to me, anyway) OmniFocus script. This one tackles one of the big missing pieces of OmniFocus: templates.

You can download the script here: Templates.scpt. In short, the script looks for a template folder and offers to do all the heavy lifting of creating a new instance of the template. Here's the detailed process, if you're interested:

(1) You make a template folder and some template projects. The variables are designated by a symbol of your choosing (I chose "$" as the default as a tribute to my favorite CSS preprocessor, SASS), with any variables used listed in the last paragraph of the project's note field (i.e., "$Person $Topic $Location"). Variables will be recognized in the project name and in the sub-task names, notes, and contexts. Thanks to Sven Fletcher, it also handles projects without variables gracefully.

0 - Template Folder

(2) Run the script. On the first run, the script will ask what variable you are using and whether you want to be prompted for viewing new template instances after they are made.

1 - Variable Definition

(3) Script goes hunting for templates. The script will try and find a folder that contains "Template" in its name. If it can find one, it will show you all remaining projects in that folder. If it can't, it will ask you to pick a folder that contains your templates, and you can then select from that list.

2 - Select Template

(4) You select destination folder.

3 - Select Folder

(5) You feed script variables. Based on the notes field of the project, the script will prompt you to fill in your desired values for each variable it finds.

4 - Variables

(6) Script works hard. It might take a little while for the whole thing to finish, especially if it is a big template. Be patient! The script replaces any instances of the variables in the project name, task name, task note, and task context. The task context replacement is especially neat: it looks to see if, in replacing the variable in the context, it would create a context you already have. If so, it assigns that context to the task. If not, it creates a new context in the same containing folder as the context with the variable. This process is particularly useful if you use a "Waiting" container to store multiple individual-specific waiting contexts like I do.

In addition, you can specify a relative date (from today) for any number of tasks (or the project as a whole) to start or become due. To do so, simply put "Start" or "Due" at the beginning of a new paragraph, and use the smart date syntax you usually do in OmniFocus (for example, "2d", "4d at 5pm", "3w 2d 14:00", etc). The script will pull that out, assign the calculated date to the start/ due date of that task, and then strip it out of the task notes.

(7) Script finishes. If you told it to prompt you, you will now be asked whether you want to see the new instance, which will open a new OmniFocus window with that project focused on.

5 - View in Context

(8) Admire results.

6 - Completed Templates

Many thanks to the Omni Group for making such an amazing tool (with such excellent Applescript support). Also, I took a lot of inspiration from Curt Clifton's template script, which is amazing.

If you're interested in seeing my past projects, you can check out the Project page. If you want to see what my distracted mind comes up with next, you can follow me on Twitter or subscribe to the RSS feed.