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.
commandKeyDown (Boolean r/o) • Is the Command key pressed?
controlKeyDown (Boolean r/o) • Is the Control key pressed?
optionKeyDown (Boolean r/o) • Is the Option key pressed?
shiftKeyDown (Boolean r/o) • Is the Shift key pressed?
The following plug-in demonstrates how to access the current values of the modifier key properties:
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.
version (String r/o) • Deprecated: Recommend using either userVersion or buildVersion. For backwards compatibility with existing scripts, this returns the same result as buildVersion.versionString. We recommend using either the user-visible userVersion or the internal buildVersion instead, which are more clear about which version they’re returning and provide their results as Version objects which can be semantically compared with other Version objects.
userVersion (Version r/o) • The user-visible version number for the app. See also buildVersion.
buildVersion (Version r/o) • The internal build version number for the app. See also userVersion.
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:
equals(version: Version) → (Boolean) • Returns true if the receiving Version is equal to the argument Version.
atLeast(version: Version) → (Boolean) • Returns true if the receiving Version is at the same as or newer than the argument Version.
isAfter(version: Version) → (Boolean) • Returns true if the receiving Version is strictly after the argument Version.
isBefore(version: Version) → (Boolean) • Returns true if the receiving Version is strictly before the argument Version.
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
}