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


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.") } else if (currentDeviceType === DeviceType.visionPro){ console.log("This device is an Apple Vision Pro.") } else { console.log("This is an unknown type of device.") }

Determining current device using JavaScript switch statement:

Device Type (Switch Statement)


switch(Device.current.type){ case DeviceType.iPhone: console.log("This device is an iPhone.") break; case DeviceType.iPad: console.log("This device is an iPad.") break; case DeviceType.mac: console.log("This device is a Mac.") break; case DeviceType.visionPro: console.log("This device is an Apple Vision Pro.") break; default: console.log("This is an unknown type of device.") }

A script that checks operating system:

Operating System Version


Device.current.operatingSystemVersion //--> [object Version: 14.4.1] {versionString: "14.4.1"}

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){ currentVersion = Device.current.operatingSystemVersion requiredVersion = new Version("11") result = currentVersion.atLeast(requiredVersion) if (result === false){ title = "INCOMPATIBLE OS" 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 { title = "INCOMPATIBLE DEVICE" 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 }