Skip to main content
Search the accessibility tree for elements matching specific criteria. Supports filtering by role, name, value, and text content. Can return all matches, a count, or specific matches by index.

Usage

agent-desktop find [OPTIONS]

Parameters

--app
string
Filter search to a specific application by name. If omitted, searches the focused application.
--role
string
Match by accessibility role (e.g., button, textfield, checkbox, link, menuitem).
--name
string
Match by accessible name or label. Case-insensitive substring match.
--value
string
Match by current value. Case-insensitive substring match.
--text
string
Match by text in name, value, title, or description. Case-insensitive substring match.
--count
boolean
default:"false"
Return only the match count, not the actual elements.
--first
boolean
default:"false"
Return only the first match.
--last
boolean
default:"false"
Return only the last match.
--nth
number
Return the Nth match (0-indexed).

Response (Default)

matches
array
Array of matching elements.

Response (Count Mode)

count
number
Total number of matching elements.

Response (First/Last/Nth Mode)

match
object
Single matching element (same structure as elements in matches array), or null if no match found.

Examples

Find all buttons

agent-desktop find --role button --app Finder
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "matches": [
      {
        "ref": "@e1",
        "role": "button",
        "name": "Back",
        "interactive": true,
        "path": ["window:Documents", "group:Toolbar"]
      },
      {
        "ref": "@e5",
        "role": "button",
        "name": "Forward",
        "interactive": true,
        "path": ["window:Documents", "group:Toolbar"]
      },
      {
        "ref": "@e12",
        "role": "button",
        "name": "List View",
        "interactive": true,
        "path": ["window:Documents", "group:View Options"]
      }
    ]
  }
}

Find element by name

agent-desktop find --name "Save" --app TextEdit
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "matches": [
      {
        "ref": "@e8",
        "role": "button",
        "name": "Save",
        "interactive": true,
        "path": ["window:Untitled", "group:Toolbar"]
      },
      {
        "ref": "@e23",
        "role": "menuitem",
        "name": "Save",
        "interactive": true,
        "path": ["menubar", "menu:File"]
      }
    ]
  }
}

Find text field with specific value

agent-desktop find --role textfield --value "quarterly report"
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "matches": [
      {
        "ref": "@e7",
        "role": "textfield",
        "name": "File Name",
        "value": "quarterly report",
        "interactive": true,
        "path": ["window:Save", "group:Content"]
      }
    ]
  }
}

Count matches

agent-desktop find --role checkbox --count --app "System Settings"
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "count": 12
  }
}

Get first match

agent-desktop find --text "OK" --first
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "match": {
      "ref": "@e14",
      "role": "button",
      "name": "OK",
      "interactive": true,
      "path": ["window:Preferences", "group:Dialog"]
    }
  }
}

Get Nth match

agent-desktop find --role menuitem --nth 2
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "match": {
      "ref": "@e11",
      "role": "menuitem",
      "name": "Open…",
      "interactive": true,
      "path": ["menubar", "menu:File"]
    }
  }
}

No matches found

agent-desktop find --name "NonExistent"
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "matches": []
  }
}

First match when none exist

agent-desktop find --name "NonExistent" --first
{
  "version": "1.0",
  "ok": true,
  "command": "find",
  "data": {
    "match": null
  }
}

Error Cases

Application not found

{
  "version": "1.0",
  "ok": false,
  "command": "find",
  "error": {
    "code": "APP_NOT_FOUND",
    "message": "No windows found for app 'InvalidApp'"
  }
}

Permission denied

{
  "version": "1.0",
  "ok": false,
  "command": "find",
  "error": {
    "code": "PERM_DENIED",
    "message": "Accessibility permission not granted",
    "suggestion": "Open System Settings > Privacy & Security > Accessibility and add your terminal"
  }
}

Notes

  • All text matching is case-insensitive and uses substring matching.
  • The --text parameter searches across name, value, title, AND description fields.
  • Multiple filter parameters are combined with AND logic (all must match).
  • The search traverses the entire accessibility tree in depth-first order.
  • Only the first snapshot is taken; the command does not poll for changes.
  • The path field shows the element’s location using the format role:name for each ancestor.
  • --count, --first, --last, and --nth are mutually exclusive.

See Also

  • snapshot - Capture the full accessibility tree
  • get - Read element properties by ref
  • is - Check element states

Build docs developers (and LLMs) love