×

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

Instance Properties

Device.Type Class

Class properties for the Device.Type class:

Examples

Here are some examples of the use of the Device class:

Current Device


Device.current

Sample Results:

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 }