Repeating Tasks

Omni Automation in OmniFocus 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 instance functions of the Task.RepetitionRule class:

Date/Time of the Next Task Repetition

var task = document.windows[0].selection.tasks[0] if(task && task.repetitionRule){ console.log(task.name, task.repetitionRule.firstDateAfterDate(new Date())) }

The Task.RepetitionMethod Class

New Repeating Task

var task = new Task("My Weekly Task") var ruleString = "FREQ=WEEKLY" var repetitionMethod = Task.RepetitionMethod.DueDate task.repetitionRule = new Task.RepetitionRule(ruleString, repetitionMethod) var taskID = task.id.primaryKey URL.fromString("omnifocus:///task/" + taskID).open()

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

Stop Repetition

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 for Selected Task

/*{ "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; })();