# ui_act

Act on an element of the latest `ui_snapshot` by id, through the accessibility API: invoke, set a value, focus, toggle, expand. It does not need the pointer or the front. An id from an older snapshot that no longer exists is `element_gone`; the call never falls back to pixels.

**In short:** Risk class [`control`](https://docs.cmdop.ai/reference/tools.md#risk-classes). Over MCP call `ui_act`; over HTTP send `"tool": "ui_act"` to [`POST /api/v1/call`](https://docs.cmdop.ai/reference/http/post-call.md).

## Arguments

Over MCP every tool also takes `machine`: the machine's name or id, optional when only one machine is online.

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `action` | `"focus" | "toggle" | "expand" | "collapse" | "invoke" | "set_value" | "select_text"` | yes |  |
| `element` | `string` | yes | Element id from the latest `ui_snapshot`. |
| `observe` | `"none" | "ui" | "image"` | no |  Default: `"none"`. |
| `value` | `string` | no | The new value for `set_value`. |

## Result

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `audit_id` | `string` | yes | Id of the audit line on the machine. |
| `dispatched` | `boolean` | yes |  |
| `foreground_changed` | `boolean` | yes | The frontmost app or window changed because of the action. |
| `observation` | `object` | no |  |
| `settled_ms` | `integer` | yes | How long the screen took to go quiet after the action, in milliseconds. |

## Examples

**MCP**

```json
{
  "name": "ui_act",
  "arguments": {
    "machine": "<machine>",
    "element": "<element>",
    "action": "<action>"
  }
}
```

**HTTP**

```bash
curl -sS -X POST "https://<contour>.cmdop.ai/api/v1/call" \
  -H "Authorization: Bearer $CMDOP_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"machine":"<machine>","tool":"ui_act","args":{"element":"<element>","action":"<action>"}}'
```

## Limits

The call times out after 20 s (`timed_out`). Available since version 0.0.2. A refused or failed call returns one of the [error codes](https://docs.cmdop.ai/reference/errors.md).
