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. 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_clickwith 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. 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. 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. 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.
| Approach | Cost per step | Accuracy | Coverage | Knows state (enabled, value) | Takes over the cursor | Needs permission |
|---|---|---|---|---|---|---|
| 1. Screenshot, guess coordinates | High: an image every step | Low: coordinates are guessed | Widest: anything visible | ✗ No | ✓ Yes | Yes: screen capture and input |
| 2. Numbered marks (set-of-mark) | High: image plus a detection model | Medium: depends on detection | Wide: what the detector finds | ✗ No | ✓ Yes | Yes: screen capture and input |
| 3. App API or script | Low: one command | High | Narrow: only apps that support it | Depends on the app | ✗ No | Depends (macOS: Automation) |
| 4. Accessibility tree | Low: a block of text | High: exact positions | Medium: 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.
Acting on a ref without moving the cursor 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.
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.
- Structured text instead of images. The model reads roles, names and values. It does not have to find a button in pixels.
- A ref per element, from one snapshot. Agent Desktop's refs belong to the snapshot that produced them. When the UI changes, a stale or ambiguous ref is rejected instead of guessed, and the agent takes a new snapshot.
- Acting without the pointer (phase 2, shipped in 0.10.0). Agent Desktop's ref actions go through the accessibility API without moving the pointer or taking focus.
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.
ui_snapshot, text form
- [e1] AXWindow "Export" (40,20 320×210)
- [e2] AXGroup (56,56 288×112)
- [e3] AXTextField = "report" desc="File name" (150,62 180×24) focused
- [e4] AXTextField/AXSecureTextField = ‹masked› desc="Password" (150,94 180×24)
- [e5] AXCheckBox "Open when done" = 1 (150,128 150×20)
- [e6] AXButton "Cancel" (196,184 72×28)
- [e7] AXButton "OK" (276,184 72×28)
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
- Native Mac apps:
ui_snapshot. - Web pages:
browser_snapshot, which reads the page structure from the browser. - Custom-drawn content such as canvases, which has no accessibility tree:
screenshotandmouse, as before.
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:
- Acting by ref is new in 0.10.0. Until then OpenAB Computer only read the tree.
Agent Desktop could already click, type, set values and move focus by ref without moving the
pointer. Since 0.10.0,
ui_actionpresses, sets values and moves focus by ref without moving the cursor too. Drags, gestures and custom-drawn content still go throughmouse, and there the real cursor still moves. - Refs. Since 0.10.0 the tool keeps the last four snapshots for five minutes. Before acting it checks that the element is still there, with the same role and in the same window, and refuses a stale ref instead of guessing a replacement. Agent Desktop stores a map from each ref to evidence of the element's identity, and checks it is the same element before acting.
- Platforms. OpenAB Computer reads the tree on macOS only. Agent Desktop covers macOS, Windows and Linux.
- Shape.
ui_snapshotis one tool in a remote MCP server, used by an agent on another machine. Agent Desktop runs locally as a CLI, a C library or a stdio MCP server.
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
- ui_snapshot → [e7] AXButton "OK" (276,184 72×28)
- ui_action { snapshot_id: "snap-…", ref: "e7", action: "press" }
- → AXPress on e7; the cursor does not move
- ui_snapshot again to check the result
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.