Device Class
In some scenerios, it is beneficial for an Omni Automation script to derive information about the device running the script. For example, a plug-in that creates new views might need to adjust its actions based upon whether the device running the script is an iPad or an iPhone. The Device class can be used to derive information about the device and operating system on which the script is executed.
Class Properties
current (Device r/o) • The device the current application is running on.
Instance Properties
iOS (Boolean r/o) • A convenience property whose value is true on iPhone and iPad devices.
iPad (Boolean r/o) • A convenience property whose value is true only on iPad devices, but not on iPhone devices.
mac (Boolean r/o) • A convenience property whose value is true only on Mac devices.
operatingSystemVersion (Version r/o) • The current operation system version running on the device.
type (Device.Type or null r/o) • The general type of the current device.
Device.Type Class
Class properties for the Device.Type class:
iPad (Device.Type r/o) • An iPad.
iPhone (Device.Type r/o) • An iPhone.
mac (Device.Type r/o) • A Macintosh computer.
all (Array of Device.Type r/o) • An array of all items of this enumeration.
Examples
Here are some examples of the use of the Device class:
Current Device
Device.current
Sample Results:
- Mac: {[object Device] {iOS: false, iPad: false, mac: true, operatingSystemVersion: [object Version: 10.15.5], type: [object DeviceType: mac]}
- iPad: {[object Device] {iOS: true, iPad: true, mac: false, operatingSystemVersion: [object Version: 14.2], type: [object DeviceType: iPad]}
- iPhone: {[object Device] {iOS: true, iPad: false, mac: false, operatingSystemVersion: [object Version: 14.4], type: [object DeviceType: iPhone]}
A script that checks device type:
Device Type
var currentDeviceType = Device.current.type
if (currentDeviceType === DeviceType.iPhone){
console.log("This device is an iPhone.")
} else if (currentDeviceType === DeviceType.iPad){
console.log("This device is an iPad.")
} else if (currentDeviceType === DeviceType.mac){
console.log("This device is a Mac.")
}
A script that checks operating system:
Operating System
if (Device.current.iOS){
console.log("This device is running iOS.")
} else if (Device.current.mac){
console.log("This device is running macOS.")
}
Here is a script that checks to see if the current device is a Mac running macOS 11 (Big Sur) or newer:
Device/OS Version Check (macOS Big Sur or newer)
if (Device.current.mac){
var currentVersion = Device.current.operatingSystemVersion
var requiredVersion = new Version("11")
var result = currentVersion.atLeast(requiredVersion)
if (result === false){
var title = "INCOMPATIBLE OS"
var msg = "This script requires macOS 11.0 or newer. "
msg = msg.concat("The current operating system version is: " + currentVersion.versionString)
new Alert(title, msg).show()
}
} else {
var title = "INCOMPATIBLE DEVICE"
var msg = "This plug-in requires a device running macOS 11.0 or newer."
new Alert(title, msg).show()
}
A script that sets the keyboard to be displayed for the specified text input field in a plug-in form viewed on an iPhone:
Set Keyboard Type for Device (iPhone)
if (Device.current.type === DeviceType.iPhone){
textInputField.keyboardType = KeyboardType.PhonePad
}