← Dev notes

OpenAB Computer can now read the macOS accessibility tree

Have you ever wondered how an agent actually manages to click exactly the right button in an app on a remote computer's desktop when you ask it to?

OpenAB Computer 0.9.0 adds ui_snapshot, an MCP tool that reads the accessibility tree of a Mac app and returns it as JSON. An agent can now see the buttons, fields and labels in a window as text, with their positions on screen, instead of working them out from a screenshot.

How does an agent click the right button?

Computer use means letting an agent operate a computer: look at the screen, move the mouse, click and type. Clicking is easy. Clicking the right thing is hard: for a Save button on the screen, the agent has to know where it is, whether it really is a button, and whether it can be pressed right now.

There are roughly four common ways to do it.

  1. 1. Look at a screenshot and guess coordinates. At every step the agent takes a screenshot, the model works out where the button is and returns x and y, the mouse moves there and clicks, and another screenshot checks the result.

    Pros: it is the most general. Any app whose screen you can see can be operated, including games and custom-drawn interfaces.

    Cons: every step sends an image, which costs tokens and time. The coordinates are a guess, so clicks often land off target when a button is small or the resolution or scaling differs. The model sees pixels: it cannot tell a button from a picture that looks like one, and it does not know whether a button is greyed out. Clicking moves the real cursor, so you cannot use that computer while the agent works.

    Examples: Anthropic's computer use tool works this way. Claude receives screenshots and returns actions such as left_click with an [x, y] in screenshot pixels, which your code carries out. Its docs list clicks that land in the right area but miss a very small target, and suggest the zoom action for a closer look. OpenAI's computer use tool, built on its Computer-Using Agent model (CUA), also looks at screenshots and returns mouse and keyboard actions with x and y; screenshots count as image input. OpenAI also offers a second mode in which the model writes code (Playwright or PyAutoGUI) to drive the interface.

  2. 2. Number the screenshot first, then ask the model to pick (often called set-of-mark). Another vision model first detects the elements on screen, draws a box around each and numbers them. The agent then answers "press 7".

    Pros: the model does not have to work out coordinates, so it misses far less often.

    Cons: every step still sends an image, and there is now a second model. If the detector misses an element or boxes the wrong thing, the agent goes wrong with it. It still does not know an element's state, such as whether it can be pressed or what its value is.

    Examples: the idea comes from the Set-of-Mark prompting paper, which splits an image into regions with an off-the-shelf segmentation model, overlays numbers or boxes, and has the model answer from the marked image. Microsoft's OmniParser applies it to screenshots: a detection model finds the interactable regions, a caption model describes what each element does, and the screenshot becomes a structured list of elements.

  3. 3. Use the app's own API or scripts. For example, an AppleScript that tells Finder to open a folder, or a command-line tool.

    Pros: the most precise, and no screen is needed.

    Cons: every app is different, many apps have no such interface, and the agent has to learn each app first.

    Example: Apple's AppleScript controls scriptable Mac apps and parts of macOS directly. Apps that are not scriptable are out of its reach.

  4. 4. Read the accessibility tree. Operating systems already have an interface built for screen readers: the macOS Accessibility API, Windows UI Automation and Linux AT-SPI. Web pages have the browser's accessibility tree. It describes buttons, fields and menus as a tree: the role, the label, the current value, whether the element can be used, and its exact position on screen.

    Pros: the result is text, which is cheap and fast. The system gives the kind of element, its name and its state directly. Positions are exact. Each element can get a ref, and the agent can later say "press this ref", without even moving the cursor.

    Cons: it depends on how well the app supports it. Custom-drawn interfaces, canvases and games are often empty in the tree. It needs the Accessibility permission. A complex interface makes a large tree, so depth and node count need limits. When the screen changes, old refs stop working and the tree has to be read again.

    Example: Vercel's Agent Desktop takes this route. It reads a desktop app's accessibility tree and returns it as JSON with a ref for every element an agent can act on; ref actions do not move the pointer or take focus. It covers macOS, Windows and Linux.

The four approaches side by side
ApproachCost per stepAccuracyCoverageKnows state (enabled, value)Takes over the cursorNeeds permission
1. Screenshot, guess coordinatesHigh: an image every stepLow: coordinates are guessedWidest: anything visible✗ No✓ YesYes: screen capture and input
2. Numbered marks (set-of-mark)High: image plus a detection modelMedium: depends on detectionWide: what the detector finds✗ No✓ YesYes: screen capture and input
3. App API or scriptLow: one commandHighNarrow: only apps that support itDepends on the app✗ NoDepends (macOS: Automation)
4. Accessibility treeLow: a block of textHigh: exact positionsMedium: standard UI; canvas and games often empty✓ Yes, from the system✗ No, when acting by ref*Yes: Accessibility

* Acting by ref without moving the cursor is ui_action, shipped in OpenAB Computer 0.10.0. Drags, gestures and custom-drawn content still go through mouse, which moves the cursor.

Screenshot, guess coordinatesUntitledSave changes?CancelSaveguess: (266, 153)just missedscreenshots sent1 Screenshot2 Model guesses x, y3 Click: just off the button4 Screenshot again to checkimage tokens
Read the accessibility treeUntitledSave changes?CancelSavecenter of e3cursor did not move[e1] AXWindow "Untitled"[e2] AXButton "Cancel" (168,126 56×22)[e3] AXButton "Save" (232,126 56×22)1 Read the tree: text, no image2 Pick ref e3: AXButton "Save"3 Act on e3: lands exactly, cursor stays4 Read the tree again to checkimage tokens: none

Acting on a ref without moving the cursor is ui_action, shipped in OpenAB Computer 0.10.0.

Animation: approach 1 next to approach 4. On the left, the agent takes a screenshot, the model guesses coordinates, and the click lands just below the small Save button, so it takes another screenshot; each screenshot adds image tokens. On the right, the agent reads the accessibility tree as text, picks ref e3 (AXButton "Save") and acts on it: the press lands on the button and the cursor does not move. Acting by ref is ui_action, shipped in OpenAB Computer 0.10.0.

Why we chose the accessibility tree

In OpenAB Computer the agent is somewhere else, so the most expensive part is sending screenshots back and forth. The accessibility tree turns each step from "send an image, guess a coordinate" into "read some text, pick a ref". It also fixes the missed clicks, because positions are not guessed. For most standard Mac apps that is enough. It does not cover everything, so we kept screenshots and use all three together: ui_snapshot reads the accessibility tree of native apps, browser_snapshot reads the browser's accessibility tree for web pages, and whatever the tree cannot see (canvases, custom-drawn interfaces) goes back to screenshot and mouse.

The research behind this

This work started with a research report we published for the community on Muse. It compares three projects. OpenCode Browse lets an agent drive your own logged-in browser on your machine. Vercel Agent Desktop lets an agent drive desktop apps through the accessibility tree: it returns structured JSON with a ref for each element, and acts on those refs without moving the pointer or taking focus. OpenAB Computer lends a whole machine to an agent somewhere else. For that remote agent, the report found, the screenshot loop is the main cost.

We took what Agent Desktop does well, reading the accessibility tree as structured data with refs instead of guessing from pixels, and made it an OpenAB Computer MCP tool, ui_snapshot. The remote agent can now read native apps as structured text, not only the browser.

Why the screenshot loop was not enough

Until now, an agent using OpenAB Computer on a Mac worked in a loop: take a screenshot, guess where a button is, click it with mouse, then take another screenshot to check.

A community user, ttmuse, described the cost of that loop on issue #67. They use OpenAB Computer every day as the hands of a cloud agent that drives a home Mac. Every step costs image tokens, small targets get missed, and the real cursor is taken over while the agent works.

The issue had been waiting for a real user. The comment showed there was one, so we raised its priority and started with macOS.

Screenshot loopScreenshota full image, every stepModel guesses x, ysmall targets get missedmouse moves and clicksthe real cursor is taken overScreenshot again to checkanother imageimage tokens With ui_snapshotui_snapshottext and JSON, no imageFind the node by role and titleAXButton "OK" → ref e7 and its frameAct on the refui_action (0.10.0): the cursor staysui_snapshot again to checka new snapshot with new refsimage tokens: none
Animation: the screenshot loop next to ui_snapshot. On the left, every step sends a screenshot, the model guesses coordinates, mouse moves the real cursor to click, and another screenshot checks the result, so image tokens add up. On the right, ui_snapshot returns text; the agent finds the node by role and title, acts on its ref with ui_action (shipped in 0.10.0) without moving the cursor, then takes a new snapshot. No image is sent.

What we learned from Agent Desktop

Before writing code we read Vercel Labs' Agent Desktop closely: its README, its concept docs and its macOS code. Agent Desktop reads the accessibility tree of a desktop app and returns it as JSON, with a ref for every element an agent can act on. Three of its ideas shaped our plan: the first two are in ui_snapshot, and the third shipped in 0.10.0 as ui_action.

Issue #67 listed calling Agent Desktop from OpenAB Computer as one option, and weighed less code to own against an external dependency and its release cadence. We decided to make the accessibility tree one of OpenAB Computer's own MCP tools, in the Swift daemon that already serves screenshot, mouse and key (PR #93).

What ui_snapshot returns

By default it reads the focused window of the frontmost app. app (a bundle id or name), pid, window and all_windows pick another target.

Each node carries its role, title, value and description, whether it is enabled or focused, and a frame. The frame uses the same display points as screenshot and mouse, so an agent can aim a click at a node without looking at the screen first. Every node also gets a ref (e1, e2, …) that is unique within that snapshot's id.

(0,0)ExportFile namereportPassword••••••Open when doneCancelOK

ui_snapshot, text form

  1. [e1] AXWindow "Export" (40,20 320×210)
  2. [e2] AXGroup (56,56 288×112)
  3. [e3] AXTextField = "report" desc="File name" (150,62 180×24) focused
  4. [e4] AXTextField/AXSecureTextField = ‹masked› desc="Password" (150,94 180×24)
  5. [e5] AXCheckBox "Open when done" = 1 (150,128 150×20)
  6. [e6] AXButton "Cancel" (196,184 72×28)
  7. [e7] AXButton "OK" (276,184 72×28)
Animation: a made-up dialog and the tree ui_snapshot returns for it, built node by node in the tool's text form. Each node has a role, a title or value, a ref (e1 to e7) and a frame. Frames are in screen points, the same coordinates screenshot and mouse use, so each highlighted line matches the outlined area of the dialog. The password field shows ‹masked›: the tool never reads its value. Hover over, focus or tap a line to see its frame.

Here is a real snapshot of Finder on an Apple-silicon Mac, taken with no Finder window open. The window is the desktop itself, and the two images in it are the icons of two mounted drives. The tool returns a text form for the model:

ui_snapshot snap-54785c06 · Finder (com.apple.finder) · 4 nodes · 46 ms
[e1] AXScrollArea desc="desktop" (0,0 1920×1080) disabled
  [e2] AXGroup desc="desktop" (0,0 1920×1080)
    [e3] AXImage "Data" (1823,145 64×64)
    [e4] AXImage "Backup" (1823,33 64×64)

and the same tree as JSON (an excerpt; some fields are left out):

{
  "snapshot_id": "snap-54785c06",
  "app": { "name": "Finder", "bundle_id": "com.apple.finder" },
  "node_count": 4,
  "truncated": false,
  "timed_out": false,
  "elapsed_ms": 46,
  "limits": { "max_depth": 20, "max_nodes": 300, "timeout_ms": 3000 },
  "windows": [
    { "ref": "e1", "role": "AXScrollArea", "description": "desktop",
      "enabled": false,
      "frame": { "x": 0, "y": 0, "width": 1920, "height": 1080 },
      "children": [
        { "ref": "e2", "role": "AXGroup", "description": "desktop",
          "children": [
            { "ref": "e3", "role": "AXImage", "role_description": "image",
              "title": "Data", "description": "Data", "display": 0,
              "frame": { "x": 1823, "y": 145, "width": 64, "height": 64 } }
          ] }
      ] }
  ]
}

In this one run it read four nodes in 46 ms. The drive names are replaced with generic ones here. To open the “Data” drive, an agent can double-click the center of e3's frame, (1855, 177), without taking a screenshot to find it.

Limits, timeouts and privacy

A snapshot is bounded. By default it stops at 20 levels deep or 300 nodes, and the whole call gets 3 seconds; a caller can raise these to 50 levels, 2,000 nodes and 10 seconds. Before every accessibility call the tool sets a messaging timeout of at most half a second, so an app that has stopped responding cannot block it.

When a limit or the time budget runs out, the agent gets what was read so far, flagged with truncated or timed_out, and no error. Long text is read as a 200-character prefix, so a large document is not copied whole.

Password fields are always masked. For a secure text field the tool never asks for the value and does not look inside it. Other fields are not masked.

That matters because the tree holds text a screenshot does not show: rows scrolled out of view, collapsed content, other windows. So ui_snapshot is available only to the owner profile, and it needs the macOS Accessibility permission, the same one mouse and key already use.

Which tool for which screen

Where we match Agent Desktop, and where we don't yet

The same: both read the macOS accessibility API and return JSON, not images. Both give elements refs that are valid only within one snapshot. Ours label every node; Agent Desktop's label the elements an agent can act on. Both return a partial tree instead of failing. Neither has a model inside; the calling agent runs the loop.

Different, today:

Phase 2 shipped: ui_action in 0.10.0

Phase 2 is ui_action, released in OpenAB Computer 0.10.0. With a snapshot_id and a ref it presses a button, sets a field's value, moves focus, opens a menu, confirms, cancels, or steps a value up or down, through the accessibility API and without moving the cursor. That is the part that ends the cursor takeover. Pass include_menu_bar to ui_snapshot and menu bar items get refs too. Through a switchboard, setting a value on a password field is refused unless the owner opts in.

ui_action · shipped in OpenAB Computer 0.10.0

(0,0)ExportFile namereportPassword••••••Open when doneCancelOKcursor stays here
  1. ui_snapshot → [e7] AXButton "OK" (276,184 72×28)
  2. ui_action { snapshot_id: "snap-…", ref: "e7", action: "press" }
  3. → AXPress on e7; the cursor does not move
  4. ui_snapshot again to check the result
Animation: phase 2, ui_action, shipped in OpenAB Computer 0.10.0. After a snapshot, the agent calls ui_action with the snapshot id, ref e7 and the action press. OpenAB Computer presses the OK button through the accessibility API and the cursor stays where it was. The agent then takes a new snapshot to check.

Linux (AT-SPI) is deferred as p3 in issue #102, to be picked up when a Linux machine needs it; #67 is closed now that the macOS part is done. How we test ui_action, and how much faster it is than a screenshot loop, is in the next note: OpenAB Computer 0.10.0 now supports full accessibility-tree actions: 4.7× faster and 55% fewer tokens in our test.

To try it, update to OpenAB Computer 0.10.0, give it the Accessibility permission, and call ui_snapshot and then ui_action from an agent with the owner profile.