Device App Version
The Device namespace provides access to information about the current device and its environment, including hardware characteristics, system details, screen metrics, battery status, orientation, proximity sensor state, locale and language settings, wake lock control, and network interfaces.
This API is commonly used to adapt UI layouts, behavior, and feature availability based on the device’s runtime context.
Network state and changes
Device is a global namespace; it needs no import. You can also use import { Device } from "scripting" to access the same object. These methods run in an active main-app script.
The snapshot contains:
getNetworkState() waits for an actual system path callback, with a 10-second timeout. A newly started monitor never reports a made-up initial offline value. A listener receives an asynchronous initial snapshot, then updates when these fields change; duplicate registration of the same function is ignored. removeNetworkChangeListener() without an argument removes all this Device object's network listeners. Listeners and pending queries are cleaned up when the script exits. Monitoring does not keep a script running in the background or guarantee delivery while suspended.
A satisfied path does not prove Internet, a particular TCP server, Bonjour or RSD is reachable. Test the operation itself. The API does not return SSID, cellular generation or airplane-mode settings. Device.networkInterfaces() remains the separate address-list API.
Queries reject with an error whose code identifies the failure: ERR_NETWORK_STATE_TIMEOUT (no initial system event), ERR_NETWORK_STATE_LIMIT (over 32 pending queries or 32 distinct listeners), ERR_PLATFORM_NOT_SUPPORTED (unsupported/inactive context), or ERR_PRO_REQUIRED (access denied). Listener registration can throw the same applicable access/limit errors and ERR_INVALID_ARG_TYPE. Removal remains available for cleanup. If access is revoked, the next update or call releases monitoring; no synthetic network-state callback is emitted for that error.
Orientation
Represents the physical orientation of the device.
Description
portrait: Portrait orientation, default upright positionportraitUpsideDown: Portrait orientation, upside downlandscapeLeft: Landscape orientation rotated to the leftlandscapeRight: Landscape orientation rotated to the rightfaceUp: Device is lying flat with the screen facing upwardfaceDown: Device is lying flat with the screen facing downwardunknown: Orientation cannot be determined
InterfaceOrientation
Represents the supported interface orientations for the app.
Description
portrait: Portrait orientation, default upright positionportraitUpsideDown: Portrait orientation, upside downlandscape: Landscape orientation, either left or rightlandscapeLeft: Landscape orientation rotated to the leftlandscapeRight: Landscape orientation rotated to the rightall: All supported orientationsallButUpsideDown: All supported orientations except upside down
NetworkInterface
Describes a single network interface address.
Properties
address: IP addressnetmask: Subnet maskfamily: Address family, either IPv4 or IPv6mac: MAC address (may be null depending on system restrictions)isInternal: Indicates whether the interface is internal (for example, loopback)cidr: CIDR notation, such as192.168.1.10/24
BatteryState
Represents the current battery state.
Description
full: Battery is fully chargedcharging: Device is currently chargingunplugged: Device is not connected to powerunknown: Battery state cannot be determined
Device Information
model
The device model, such as "iPhone" or "iPad".
localizedModel
The localized name of the device model.
appVersion / appBuildNumber
Readonly synchronous strings identifying the Scripting App, including when a script runs in an extension. appVersion reads CFBundleShortVersionString; appBuildNumber reads CFBundleVersion. Build numbers stay strings (they can contain dots or leading zeros). If the containing App cannot be read, the running bundle is used; a missing value is an empty string.
Device is an injected global, so no import is required. The existing import alias is also supported:
These values identify Scripting, independently of a script's own version and the OS version. They require no permission or network access.
systemVersion
The current operating system version, for example "18.2".
systemName
The name of the operating system, such as "iOS", "iPadOS", or "macOS".
isiPad / isiPhone
Indicates whether the current device is an iPad or an iPhone.
screen
Screen metrics:
width: Screen width in logical pixelsheight: Screen height in logical pixelsscale: Screen scale factor (for example, 2 or 3)
Battery and Sensors
batteryState
The current battery state.
batteryLevel
The current battery level, expressed as a value between 0.0 and 1.0.
proximityState
The state of the proximity sensor.
true indicates that the device is close to the user, such as during a phone call.
Orientation and Layout
isLandscape / isPortrait / isFlat
isLandscape: Indicates whether the device is in a landscape orientationisPortrait: Indicates whether the device is in a portrait orientationisFlat: Indicates whether the device is lying flat (face up or face down)
orientation
The current physical orientation of the device.
supportedInterfaceOrientations
The list of supported interface orientations. You can set this property to limit the orientations that your page supports.
Example
userConfiguredInterfaceOrientations
The list of interface orientations configured by the user. You can use this value to set supportedInterfaceOrientations to restore the default interface orientations.
Appearance and Environment
colorScheme
The current system color scheme, such as light or dark mode.
isiOSAppOnMac
Indicates whether the current process is an iPhone or iPad app running on macOS.
Locale and Language
systemLocale
The current system locale, for example "en_US".
preferredLanguages
The user’s preferred languages, for example:
systemLocales (Deprecated)
Deprecated. Use preferredLanguages instead.
systemLanguageTag
The current language tag, such as "en-US".
systemLanguageCode
The current language code, such as "en".
systemCountryCode
The current country code, such as "US".
systemScriptCode
The script code of the current locale, such as "Hans" for Simplified Chinese.
Wake Lock
isWakeLockEnabled
Retrieves whether the wake lock is currently enabled, preventing the device from automatically sleeping.
setWakeLockEnabled
Enables or disables the wake lock.
Notes:
- Available only in the Scripting app
- When enabled, the device will remain awake and not auto-lock
Battery Listeners
addBatteryStateListener
Registers a listener for battery state changes.
removeBatteryStateListener
Removes a battery state listener.
If callback is not provided, all battery state listeners are removed.
addBatteryLevelListener
Registers a listener for battery level changes.
removeBatteryLevelListener
Removes a battery level listener.
If callback is not provided, all battery level listeners are removed.
Orientation Listeners
addOrientationListener
Starts observing device orientation changes.
Notes:
- This method must be called before orientation updates are delivered
- Orientation updates do not work when system orientation lock is enabled
removeOrientationListener
Removes an orientation change listener.
If callback is not provided, all orientation listeners are removed and observation is stopped.
Proximity Listeners
addProximityStateListener
Registers a listener for proximity sensor state changes.
removeProximityStateListener
Removes a proximity state listener.
If callback is not provided, all proximity listeners are removed.
Network
networkInterfaces
Returns the network interfaces available on the device.
Return value:
- Keys are interface names (such as
en0,lo0) - Values are arrays of
NetworkInterfaceobjects associated with each interface
This method is useful for network diagnostics, retrieving local IP addresses, and debugging connectivity issues.
