In Omni Automation scripts, the application object is represented by the abbreviation: “app”. The application object is addressed by scripts to determine the current system platform, pressed modifier keys, and for opening documents. (see Application section)
Windows
01app.name
02--> OmniPlan

Documents

Although documents are the sole and primary element of the OmniPlan application, the current document is not referenced using the app object, but is referenced instead as a top-level object:
01document.name
01//--> 'Home Renovation'
For the sake of security, documents are not allowed to be accessed by scripts run in the consoles of other documents, so the application object will not return references to other documents.
01//--> these are not supported
02app.documents.length
03app.documents[0]

Document Windows

In the OmniPlan scripting implementation, windows belong to documents, and their references include their parent implied document object:
Document > Window
01document.windows.length
And the current window is always the first item in the list (array) of open windows:
01currentWindow = document.windows[0]

Document Selection

Omniplan
A document’s selection object belongs to the window class, which in turn, belongs to the parent implied document. The Selection class includes three properties whose values are a single item reference (selection, project) or arrays of references (resources, tasks) to the objects selected in the window: project, resources, and tasks
Document > Window > Selection

Omniplan Windows 10 Pro

document.windows[0].selection//--> [object Selection]document.windows[0].selection.project//--> [object Project]document.windows[0].selection.resources//--> [[object Resource]]document.windows[0].selection.tasks//--> [[object Task],[object Task],[object Task]]
01document.windows[0].selection
02//--> [object Selection]
03document.windows[0].selection.project
04//--> [object Project]
05document.windows[0].selection.resources
06//--> [[object Resource]]
07document.windows[0].selection.tasks
08//--> [[object Task],[object Task],[object Task]]
For example, here’s a simple script for getting the titles of the selected tasks:
selectedTasks = document.windows[0].selection.taskstaskTitles = selectedTasks.map((task)=>{return task.title})
01selectedTasks = document.windows[0].selection.tasks
02taskTitles = selectedTasks.map((task)=>{returntask.title})

Project

A Project represents the contents of an OmniPlan document, and when writing scripts that target the content of the current document, the project becomes the topmost object, providing properties whose values are references to the scenarios (actual and baselines) the project contains.
01document.project.title
02//-->'90-Day Blank Project'
03
04// The Project is the topmost object and can be referenced using the “this” keyword
05this.title
06//-->'90-Day Blank Project'
07
08// Since the Project is the top-level item, it is implied and so you can simply use the property name
09title
10//-->'90-Day Blank Project'

Scenarios

A Scenario represents a set of tasks and resources and associated schedules. The actuals for a project are one scenario, and saved baselines are the others.
The project property “actual” references the current scenario, which has properties of its own, such as hasFixedEndDate:
01actual
02//--> [objectScenario]
03actual.hasFixedEndDate
04//-->false
The project property baselineNames provides an array of the names of any other scenarios, and references to those scenarios can be derived using the baselineNamed(…) scripting method:
01baselineNames
02//--> [Baseline A,Baseline B]
03baselineNamed('Baseline B')
04//--> [objectScenario]
Also note that an instance of the Scenario class contains two properties representing the origin items of their Task and Resource elements. These “root” items are used when creating and managing additional instances of their classes.
01actual.rootTask
02//--> [object Task]
03actual.rootResource
04//--> [object Resource]

Resources

Instances of the Resources class represent the people, groups, and physical materials and equipment used by the project. A Resource is an element of a Scenario and is created and added to a scenario by using the addMember() method of the Resource class on the root resource object of the scenario.
var resc = actual.rootResource.addMember()resc.type = ResourceType.staffresc.name = 'Sala Mander'resc.email = '[email protected]'
omniplan://localhost/omnijs-run?script=try%7Bvar%20resc%20%3D%20actual%2ErootResource%2EaddMember%28%29%0Aresc%2Etype%20%3D%20ResourceType%2Estaff%0Aresc%2Ename%20%3D%20%22Sala%20Mander%22%0Aresc%2Eemail%20%3D%20%22salamander%40acmeprojects%2Ecom%22%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Create New Resource
01varresc = actual.rootResource.addMember()
02resc.type = ResourceType.staff
03resc.name = 'Sala Mander'
04resc.email = '[email protected]'
The members property of the Resource class when used with the root resource object, will return an array of references to the top-level resources for the scenario, as in this example script for getting the titles of a scenario’s top-level resources:
resourceNames = actual.rootResource.members.map((rsc)=>{return rsc.name})
Get Resource Names
01resourceNames = actual.rootResource.members.map((rsc)=>{returnrsc.name})
Creating a reference to an instance of the Resource class can be done using the resourceNamed() method of the parent instance of the Scenario class.
01actual.resourceNamed('Target Resource Title')
02//--> returns the 1st matching object reference if one exists, otherwise returns null

Tasks

A Task is anything that needs to get done in order for the project to move toward completion. Each task has attributes such as start and end dates, a completion percentage, and resource assignments.
A Task is an element of a Scenario and is created and added to a scenario by using the addSubtask() method of the Task class on the root task object of the scenario.
newTask = actual.rootTask.addSubtask()newTask.title = 'NEW TASK'
omniplan://localhost/omnijs-run?script=try%7BnewTask%20%3D%20actual%2ErootTask%2EaddSubtask%28%29%0AnewTask%2Etitle%20%3D%20%22NEW%20TASK%22%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Create a Task
01newTask = actual.rootTask.addSubtask()
02newTask.title = 'NEW TASK'
The descendents() method of the Task class when used with the root task object, will return an array of references to the tasks in the entire tree of the scenario, as in this example script for getting all the task titles of a scenario:
taskTitles = actual.rootTask.descendents().map((task)=>{return task.title})
Get All Task Titles
01taskTitles = actual.rootTask.descendents().map((task)=>{
02returntask.title
03})
The property subtasks has a value that is an array of references to the subtasks of a specified task.
Creating a reference to an instance of the Task class can be done using the taskNamed() method of the parent instance of the Scenario class.

Omniplan Windows Alternative

01actual.taskNamed('Target Task Title')
02//--> returns the 1st matching object reference if one exists, otherwise returns null