Skip to main content

Overview

Every agent-native command supports the --json flag for structured output. This makes agent-native ideal for AI agents and programmatic use.
JSON output uses pretty-printed, sorted keys for readability and consistency.

Why JSON output?

For AI agents and programmatic use:
  • Structured data that’s easy to parse and query
  • Consistent format across all commands
  • Rich metadata including element attributes, actions, and state
  • No text parsing required — direct access to all fields
  • Type safety when used with typed languages

Global pattern

Add --json to any command:
The output is always valid JSON printed to stdout, with errors printed to stderr.

Command output formats

apps

List running GUI applications.
Output
Fields:
  • name (string): Application name
  • pid (number): Process ID
  • bundleId (string | null): Bundle identifier
  • isActive (boolean): Whether app is frontmost
  • isHidden (boolean): Whether app is hidden

snapshot

Capture AX tree with refs.
Output
Fields:
  • ref (string): The ref identifier (e.g. “n1”, “n2”)
  • role (string): AX role (e.g. “AXButton”, “AXTextField”)
  • title (string | null): Element title
  • label (string | null): Accessibility label
  • value (string | null): Current value (for inputs, checkboxes, etc.)
  • enabled (boolean): Whether element is enabled
  • actions (string[]): Available AX actions
  • depth (number): Depth in the tree (0 = root)
Use the ref field to interact with elements in subsequent commands.

click

Click an element.
Output
Fields:
  • action (string): The action performed
  • success (boolean): Whether action succeeded
  • element (object): Full element metadata

fill / type

Fill or type into a field.
Output
Fields:
  • action (string): “fill” or “type”
  • success (boolean): Whether operation succeeded
  • text (string): The text that was entered
  • element (object): Full element metadata

check / uncheck

Toggle checkbox state.
Output
Fields:
  • action (string): “check” or “uncheck”
  • success (boolean): Whether operation succeeded
  • element (object): Full element metadata with updated value
The check and uncheck commands are idempotent — they check current state first and only toggle if needed.

get text / value / attr

Read element data.
Output
Output
Output

get title

Get frontmost window title.
Output

is enabled / focused

Check element state.
Output
Output

inspect

Get all attributes and actions.
Output
Fields:
  • element (object): Basic element info
  • attributes (object): All AX attributes as key-value pairs
  • actions (string[]): Available actions

find

Find elements by filters.
Output
Returns an array of full AXNode objects matching the filters.

screenshot

Capture app window.
Output
Output
Fields:
  • path (string): Path to saved screenshot
  • width (number): Image width in pixels
  • height (number): Image height in pixels

action

Perform arbitrary AX action.
Output

Parsing strategies

Python

JavaScript / TypeScript

Bash (with jq)

Error handling

When a command fails, agent-native:
  1. Prints JSON error to stderr (if --json was used)
  2. Exits with non-zero code
Example error:
stderr
Always check command exit codes or use check=True in subprocess to catch errors.

Type definitions

For TypeScript projects, you can define types for agent-native output:

Next steps

Best practices

Learn patterns for reliable AI automation

AI integration

See example workflows and integration patterns