One of the most powerful aspects of Omni Automation is its built-in support for executing scripting functions between the Omni applications. For example, an OmniPlan action can perform scripting functions in OmniFocus and return any resulting data back to the OmniPlan action, for use in the current project.

Copy OmniPlan Task to OmniFocus

NOTE: This example of the use of Omni Automation between OmniPlan and OmniFocus includes a preview of the upcoming Omni Automation support in OmniFocus. The full OmniFocus Omni Automation documentation will become available at a future date.

The following example OmniPlan action will create a new task in OmniFocus, using the name, note, project title, and end date values of the selected OmniPlan task for the name, note, tag, and due date parameters of the created task.

Such “app-to-app” scripts use the tellScript(…) and call(…) functions of the URL class to generate and execute the Omni Automation script links that perform script actions and transfer data between applications.


 01  The task selected in the OmniPlan project.

 02  The task created by the script within OmniFocus.

 03  The text of the selected task’s note is assigned to the created OmniFocus task.

 04  The name of the OmniPlan document is prepended to the note body of the created task, and is added as a tag to OmniFocus (if it doesn’t already exist).

 05  A link to the OmniFocus task is appended to the note of the selected OmniPlan task. Clicking or tapping this link will cause the created task to be displayed within OmniFocus.

 06  The end date of the the OmniPlan task is used as the due date for the created OmniFocus task.

Here is the OmniPlan action for creating a new task in OmniFocus using parameters of the OmniPlan selected task.

/*{ "type": "action", "targets": ["omniplan"], "author": "Otto Automator", "identifier": "com.omni-automation.copy-task-to-omnifocus", "version": "1.7", "description": "This action will create a new task in OmniFocus matching the parameters of the selected OmniPlan task.", "label": "Copy Task to OmniFocus", "paletteLabel": "Copy to OmniFocus" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // OmniPlan selection options: projects, tasks, or resources // AQUIRE AND STORE TASK PARAMETERS SETTINGS var task = selection.tasks[0] taskTitle = task.title.replace("\`","\\`") taskNote = task.note.replace("\`","\\`") projectName ="\`","\\`") endDateString = task.endDate.toString() // OMNIFOCUS FUNCTION (AS STRING) WITH EMBEDDED TEMPLATE TAGS var functionString = `function makeNewOFTask(){ task = new Task(\"${taskTitle}\"); task.note = \`${projectName}\\n\\n${taskNote}\`; task.dueDate = new Date(\"${endDateString}\"); tag = tagNamed(\"${projectName}\"); if(!tag){tag = new Tag(\"${projectName}\")}; task.addTag(tag); return String(; };makeNewOFTask();` // CREATE SCRIPT URL FOR THE OMNIFOCUS FUNCTION var scriptURL = URL.tellScript("omnifocus", functionString) // EXECUTE THE SCRIPT URL{ linkString = "omnifocus:///task/" + reply currentContent = task.note if (currentContent.length === 0){ task.note = linkString } else { task.note = currentContent + "\n\n" + linkString } }) }); action.validate = function(selection, sender){ // OmniPlan selection options: projects, tasks, or resources if(selection.tasks.length === 1){return true} else {return false} }; return action; }(); _;

 01-10  The metadata keys and values for the action plug-in file.

 11-51  The main function that contains all of the action components, including the validation  51-54  and processing functions:  12-49 

 12-46  The processing function of the action is passed the selection and sender objects. The selection object may contain references to the selected: projects, tasks, or resources.

 16  Store a reference to the selected task in the variable: task

 17-18  Retrieve the values of the selected task’s name and note properties. Note the use of the appended replace(…) method to “escape” any back-tick (grave accent: `) characters that may be in the selected task’s title or note. This is done because the OmniFocus function to create a new task will be sent as text containing back-tick characters to indicate multiple lines of text (strings). By escaping the back-tick characters in the selected task title and note, any conflicts with the back-tick characters in the passed function will be avoided.

 23-31  The OmniFocus function for creating a new task is converted into a single text string, to be inserted into a script URL. The function string is wrapped in back-tick characters, which are used by JavaScript to indicate a multi-line block of text. The function string is stored in the variable: functionString

 24-28  In order to pass the retrieved data from the selected OmniPlan task into the OmniFocus function, Template Tags (Template Literals) are inserted into OmniFocus function string where the task data is to be used in the creation of a new task. The template tags use this syntax: ${tagName} where the the tag name is the name of the variable containing the data to be inserted. When the OmniPlan action is executed, these tags are replaced with the retrieved data of the selected task.

 34  The tellScript(…) function of the URL class (documentation) creates an Omni Automation script URL targeting the Omni application whose name is passed into the function along with the code to be executed by the targeted application.

 37-45  Using the call(…) function of the URL class, the created script URL is executed and any result is returned to the method’s callback function. In this example, the returned data is the unique identifier string for the created OmniFocus task.

 38  A link to the created OmniFocus task is created by appending the returned task identifier to a URL targeting the OmniFocus application: omnifocus:///task/ When the resulting link is tapped or clicked in OmniPlan, the OmniFocus application will become active and display the task whose identifier is in the link URL.

 39-44  Append the link to the OmniFocus task to the end of the current note content of the selected OmniPlan task.

The OmniFocus Task Creation Function

Here is the function used in the action above to create a new task in OmniFocus using the metadata of the selected OmniPlan task. Documentation of the Omni Automation support in OmniFocus is available here.

The metadata of the selected OmniPlan task is passed into the function through the use of Template Tags (Template Literals) that are replaced with the metadata strings when the enclosing action is compiled upon execution.

function makeNewOFTask(){ task = new Task("${taskTitle}"); task.note = `${projectName}\\n\\n${taskNote}`; task.dueDate = new Date("${endDateString}"); tag = tagNamed("${projectName}") || new Tag("${projectName}"); task.addTag(tag); return String(; };makeNewOFTask();

 01-09  The function for creating a new task in OmniFocus.

 02  Create a new OmniFocus task using the name of the selected OmniPlan task and store a reference to the created task in the variable: task

 03  Set the value of the note property of the created task to the combination of the title of the OmniPlan project and the value of the note property of the OmniPlan task.

 04  Set the value of the dueDate property of the created task to a new Date instance created using the date string of the OmniPlan task’s endDate property.

 05  Use the tagName(…) method of the Database class, to generate a reference of the OmniFocus tag whose title matches the name of the OmniPlan project. If no matching tag exists, a new one will be created using the new Tag constructor.

 06  Use the addTag(…) method of the Task class to assign the tag to the created task.

 07  Return the unique identifier string of the object id of the created task as the resulting value for the function.

 08  Execute the function by appending the function call to the function body.


This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.