Repeating Tasks

Omni Automation in OmniFocus (v3.8+) provides the ability to set the repetition rules for a task. The repetitionRule property of the Task class is used to access and set any repeating parameters.

The Task.RepetitionRule Class

A Task.RepetitionRule describes a pattern of dates using a ICS formatted recurrence string (iCalendar.org) and a Task.RepetitionMethod to describe how those dates are applied to a Task.

The properties of the Task.RepetitionRule class:

The Task.RepetitionMethod Class

var task = new Task("My Weekly Task") var ruleString = "FREQ=WEEKLY" task.repetitionRule = new Task.RepetitionRule(ruleString, Task.RepetitionMethod.DueDate) var taskID = task.id.primaryKey URL.fromString("omnifocus:///task/" + taskID).open()
omnifocus://localhost/omnijs-run?script=try%7Bvar%20task%20%3D%20new%20Task%28%22My%20Weekly%20Task%22%29%0Avar%20ruleString%20%3D%20%22FREQ%3DWEEKLY%22%0Atask%2ErepetitionRule%20%3D%20new%20Task%2ERepetitionRule%28ruleString%2C%20Task%2ERepetitionMethod%2EDueDate%29%0Avar%20taskID%20%3D%20task%2Eid%2EprimaryKey%0AURL%2EfromString%28%22omnifocus%3A%2F%2F%2Ftask%2F%22%20%2B%20taskID%29%2Eopen%28%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

And to disable repetition, set the property value to null:

var task = taskNamed("My Weekly Task") task.repetitionRule = null

The Rule Info Plug-In

Aside from using the free RRULE Tool at iCalendar.org, perhaps the simplest way to derive an ICS rule string is to set up an example repeating task in OmniFocus using the standard application interface, and then use Omni Automation to retrieve the corresponding ISC rule string from the selected task. You can then use the extracted ICS rule string in your scripts to define the specified repetition parameters.

The plug-in provided below will both display the ICS string and log it to the console for you.

rule-info-sheet
/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.task-rule-info", "version": "1.1", "description": "This action will display an alert showing the ICS rule string and repetition method of the selected task or project.", "label": "Rule Info for Selected Item", "shortLabel": "Rule Info" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags if (selection.projects.length === 1){ var item = selection.projects[0] var alertTitle = "Project: " + item.name } else { var item = selection.tasks[0] var alertTitle = "Task: " + item.name } var rule = item.repetitionRule var ruleString = item.repetitionRule.ruleString var repetitionMethod = item.repetitionRule.method var msg = "" var methodName switch(repetitionMethod) { case Task.RepetitionMethod.DueDate: methodName = "Due Date" break; case Task.RepetitionMethod.Fixed: methodName = "Fixed" break; case Task.RepetitionMethod.DeferUntilDate: methodName = "Defer Until Date" break; default: methodName = "None" } msg = "ICS Rule String: " + ruleString + "\n" + "Repetition Method: " + methodName console.log(msg) new Alert(alertTitle, msg).show() }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags return ( selection.projects.length === 1 && selection.projects[0].repetitionRule != null || selection.tasks.length === 1 && selection.tasks[0].repetitionRule != null ) }; return action; })();
rule-info-in-console

DISCLAIMER