×

The Application Object

In Omni Automation, the OmniPlan application object has properties (name, version) and elements (documents, windows, etc.). In a script, the application object is represented with the term: app

If you entered just “app” in the OmniPlan console window and executed the line, the result would be a reference to the application object:

Application Object


app //--> [object Application]

To get the name of the operating system the application is running on:

Platform Property


app.platformName //--> iOS or macOS

Properties: name

The value of the name property of the application object is a string representing the name of the OmniPlan application.

Application Name


app.name //--> OmniPlan

The value of the application name property is read-only.

Properties: Key-Down Properties

The following application properties can be used by scripts on macOS to determine if the standard modifier keys are pressed when the script is run. Accordingly, you can adjust the behavior of the plug-ins you create based upon the modifier keys pressed when the plug-in is triggered by the user.

The following plug-in demonstrates how to access the current values of the modifier key properties:

modifier-key-sensor
Modifier Key Sensor
 

/*{ "type": "action", "targets": ["omnifocus","omniplan","omnigraffle","omnioutliner"], "author": "Otto the Automator", "identifier": "com.omni-automation.all.modifier-key-sensor", "version": "1.0", "description": "Displays an alert showing which modifier keys are pressed when the action is triggered.", "label": "Modifier Key Sensor", "shortLabel" : "Modifier Keys", "paletteLabel": "Keys" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var keys = new Array() if (app.commandKeyDown){keys.push("Command Key " + '\u2318')} if (app.optionKeyDown){keys.push("Option Key " + '\u2325')} if (app.shiftKeyDown){keys.push("Shift Key " + '\u21E7')} if (app.controlKeyDown){keys.push("Control Key " + '\u2303')} if (keys.length === 0){keys = ["No modifier keys were pressed."]} var alertStr = keys.join("\n") var alert = new Alert('\uF8FF' + ' Modifier Keys', alertStr) alert.show() }); action.validate = function(selection, sender){ // validation code return (app.platformName === "macOS") }; return action; })();

Properties: version

The value of the version property of the application object is a string representing the version number of the OmniPlan application.

Version 4.2 or greater of OmniPlan now includes two version properties that replace the previous version property.

The value of the application version properties are read-only.

App Version Property (deprecated)


app.version //--> "207.7.1"
App User Version Property


app.userVersion //--> [object Version: 3.11.2] app.userVersion.versionString //--> "4.2.4"
App Build Version Property


app.buildVersion //--> [object Version: 149.6.7] app.buildVersion.versionString //--> "207.7.1"

Version Objects

To create a new version object:

Create Version Object


new Version('201.33') //--> [object Version]

To extract the version string from a version object:

Get Version String


var vers = new Version('201.33') vers.versionString //--> 201.33

Comparing Versions

There are four methods you can use for comparing version objects:

Here are some example functions demonstrating the use of the listed version methods:

Prior to Installed Version?


function isBeforeCurVers(versStrToCheck){ curVers = app.userVersion curVersStr = curVers.versionString versToCheck = new Version(versStrToCheck) result = versToCheck.isBefore(curVers) console.log(versStrToCheck + ' is before ' + curVersStr + " = " + result) return result }
Is the Installed Version?


function isEqualToCurVers(versStrToCheck){ curVers = app.userVersion curVersStr = curVers.versionString versToCheck = new Version(versStrToCheck) result = versToCheck.equals(curVers) console.log(versStrToCheck + ' equals ' + curVersStr + " = " + result) return result }
Is At Least the Installed Version?


function isAtLeastCurVers(versStrToCheck){ curVers = app.userVersion curVersStr = curVers.versionString versToCheck = new Version(versStrToCheck) result = versToCheck.atLeast(curVers) console.log(versStrToCheck + ' is at least ' + curVersStr + " = " + result) return result }
Is Newer than the Installed Version?


function isAfterCurVers(versStrToCheck){ curVers = app.userVersion curVersStr = curVers.versionString versToCheck = new Version(versStrToCheck) result = versToCheck.isAfter(curVers) console.log(versStrToCheck + ' is after ' + curVersStr + " = " + result) return result }