System

Access runtime system/device info and trigger system-level actions from script.

Syntax

System()

Returns

Example

sys = System()
print("sdk=", sys.sdk())
battery = System.battery()
print("battery=", battery.percent, battery.charging)
System.toast("Macro started")
System.play_noti()
System.home()

Fields

NameDescription
devdict
Current device details: isEmulator, Android API level sdk, language code, darkmode, touch support, and capture readiness. Read again to get updated details.
batterydict
Current battery details: percent from 0 to 100, charging, temperature in degrees Celsius, and health text. Unavailable percent or temperature is -1; unknown health is "unknown". Read again to update.
screendict
Current screen details: width and height in pixels, density scale, dpi, and orientation as display rotation in degrees (0, 90, 180, or 270). Read again after rotating the device.
memorydict
Current system memory: avail, total, and the low-memory threshold in bytes; low indicates that available memory is low. Read again to update.

Methods

21 methods

System.time_ms

Read the current date and time as milliseconds since 1970-01-01 00:00:00 UTC.

Syntax

System.time_ms()

Returns

Number — Milliseconds since 1970-01-01 00:00:00 UTC.

Example

# Query Android or request a documented system action
started = System.time_ms()
wait(100)
print(System.time_ms() - started)

System.app_version

Read the installed CogniTab version name.

Syntax

System.app_version()

Returns

String — The CogniTab version name, or "unknown" if unavailable.

Example

# Query Android or request a documented system action
print(System.app_version())

System.variant

Get the stable code of the macro variant selected for this run.

Syntax

System.variant()

Returns

String — Variant code such as `default` or `pro_plus`.

Example

# Branch by the current macro variant
if System.variant() == "pro_plus":
    print("Pro Plus")

System.open

Open the launchable activity of an installed Android app. CogniTab resolves the standard or Android TV launcher activity from the package name, so the activity class is not required.

Syntax

System.open(package_name)

Parameters

NameDescription
package_nameString
Android application package name, for example `com.android.settings`.
Required · Positional or named
No default

Returns

Boolean — `True` when Android accepts a launch intent; `False` when the app is unavailable, has no launchable activity, or cannot be opened.

Example

# Open Android Settings and handle an unavailable target
opened = System.open("com.android.settings")
if not opened:
    System.toast("App is unavailable")

System.sdk

Read the Android API level used by this device.

Syntax

System.sdk()

Returns

Number — Android API level as a number.

Example

# Query Android or request a documented system action
print(System.sdk())

System.language

Get current language code.

Syntax

System.language()

Returns

String — Locale language code (for example `en`, `vi`).

Example

# Query Android or request a documented system action
print(System.language())

System.dpi

Get current screen DPI.

Syntax

System.dpi()

Returns

Number — Display density DPI.

Example

# Query Android or request a documented system action
print(System.dpi())

System.darkmode

Check if dark mode is enabled.

Syntax

System.darkmode()

Returns

Boolean — `True` when dark mode is active.

Example

# Query Android or request a documented system action
if System.darkmode():
    print("Dark mode")

System.play_noti

Play system notification sound.

Syntax

System.play_noti()

Returns

None — No return value.

Example

# Query Android or request a documented system action
System.play_noti()

System.toast

Show a brief Android message. Lists, dictionaries, and other structured values are shortened to keep the message readable.

Syntax

System.toast(text)

Parameters

NameDescription
textAny
Toast text or structured value to display compactly.
Required · Positional or named
No default

Returns

None — No return value.

Example

# Query Android or request a documented system action
System.toast("Macro started")

System.stop

Stop the current macro immediately from script.

Syntax

System.stop()

Returns

None — Stops execution; no return value is observed.

Example

# Query Android or request a documented system action
if Storage.get("stop_requested", False):
    System.stop()
print("Still running")

System.minimized_dock

Query or adjust the minimized overlay dock. The point uses the same coordinate scale and anchor rules as Point-based click targets; width and height are current-screen pixels.

Syntax

System.minimized_dock(point=None, *, width=None, height=None, alpha=None, mode=None)

Parameters

NameDescription
pointPoint?
Optional top-left dock position.
Optional · Positional or named
Default: None
widthNumber?
Optional minimized dock footprint width in pixels. While a collapsed floating panel is attached, the dock uses its natural size; the requested size is retained and reapplied when the attachment is gone.
Optional · Keyword only
Default: None
heightNumber?
Optional minimized dock footprint height in pixels. While a collapsed floating panel is attached, the dock uses its natural size; the requested size is retained and reapplied when the attachment is gone.
Optional · Keyword only
Default: None
alphaNumber?
Optional dock opacity from 0.2 to 1.0.
Optional · Keyword only
Default: None
modeString?
Optional dock presentation: icon, row, or hidden. icon retains the open button for a collapsed floating panel. hidden lasts for this run and keeps a bottom-left Stop button when no visible floating panel Stop button is available; when the panel is collapsed, this emergency window also provides its open button.
Optional · Keyword only
Default: None

Returns

dict — Applied state with `applied`, `x`, `y`, `width`, `height`, `alpha`, `mode`, and optional `reason`.

Example

# Move, resize, and collapse the minimized dock for this run
System.minimized_dock(Point(24, 120), width=72, height=36, alpha=0.85, mode="icon")

System.send_key

Send one Android key down/up pair to the currently focused text editor through Accessibility on Android 13 or later. Sends key events without locating keys on the on-screen keyboard.

Syntax

System.send_key(key)

Parameters

NameDescription
keyString|Number
Android key name, case-insensitive with optional `KEYCODE_` prefix, such as `ENTER`, `TAB`, `ESCAPE`, `DEL`, `DPAD_LEFT`, `A`, or `F1`; or a positive whole Android keycode, such as `66` for Enter. Whitespace around names is ignored.
Required · Positional or named
No default

Returns

Boolean — `True` when both key events are dispatched; `False` on Android 12L or earlier, for an unsupported key, without an active editor input connection, or when dispatch fails. The target app decides how to handle the key; verify its screen before continuing. This does not send a system-wide hardware key or confirm that the app handled it.

Example

# Send keys to the focused text field by name or Android keycode
sent = System.send_key("ENTER")
System.send_key(key="TAB")
System.send_key(66)

System.back

Ask Android to go back, like pressing the Back button.

Syntax

System.back()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.back())

System.home

Ask Android to open the home screen.

Syntax

System.home()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.home())

System.recent

Open recents screen.

Syntax

System.recent()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.recent())

System.noti

Open notifications shade.

Syntax

System.noti()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.noti())

System.lockscreen

Lock the current screen.

Syntax

System.lockscreen()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.lockscreen())

System.powerdialog

Open power dialog.

Syntax

System.powerdialog()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.powerdialog())

System.quicksetting

Open Android quick settings.

Syntax

System.quicksetting()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.quicksetting())

System.screenshot

Ask Android to take a screenshot.

Syntax

System.screenshot()

Returns

Boolean — `True` if Android accepts the action, otherwise `False`.

Example

# Query Android or request a documented system action
print(System.screenshot())