# Drive an iOS simulator from the command line

Read an iOS simulator's screen, tap, type, take screenshots and install apps from the terminal on macOS.

On macOS, Karagöz runs the same commands on a booted iOS simulator as on an Android emulator, with the same flags, output and error codes. It reads the screen with a Swift helper it compiles on first use, and runs `simctl` for screenshots and apps. Taps, swipes and keys go to the simulator’s input service, and `text` goes through XCUIAutomation. On a Mac that never had Xcode 27, input goes through Karagöz’s runner inside the simulator.

## 1. Before you start

- Xcode, opened once. The Command Line Tools alone have no `simctl`, and no `swiftc` for the helper.
- A booted simulator: `xcrun simctl boot <name>`.
- For input (`tap`, `long-press`, `double-tap`, `swipe`, `text` and `key`): Xcode 27 or newer. On a Mac that never had Xcode 27, input goes through Karagöz’s runner instead.
- For `text` with Xcode 27 or newer: a simulator on iOS 27 or newer.
- Karagöz: [Install](https://karagozmcp.com/docs/install/).

## 2. Find the simulator

```console title="~/app"
$ karagoz devices
Found 2 devices:
  Medium_Phone_API_37.0 • emulator-5554                        • emulator  • Android 17 (API 37) • device
  iPhone 17 Pro         • 4E70BFCA-5FC6-49B5-92EC-48E265B2D50F • simulator • iOS 27.0            • Booted

Pick one with --device <id or name>, or set KARAGOZ_DEVICE.
Missing a device? Run karagoz doctor.
```

Only a simulator in state `Booted` is usable. With more than one device listed, pass `--device` with the simulator’s UDID or name (`iPhone 17 Pro`) in each command, or set `KARAGOZ_DEVICE` once.

The samples below come from other simulators, so their `device` ids differ from this list.

For more information, see [`devices`](https://karagozmcp.com/docs/commands/devices/).

## 3. Read the screen

`karagoz ui-tree` prints the frontmost app’s accessibility tree, or SpringBoard’s on the home screen. An iPhone 17 home screen (Xcode 27; children cut short):

```json
{
  "device": "27024DC1-EDB0-4BF2-8010-08FE3936BAB6",
  "rotation": 0,
  "root": {
    "role": "Application",
    "label": " ",
    "bounds": [0, 0, 1206, 2622],
    "children": […]
  }
}
```

A node from the same tree:

```json
{
  "role": "Button",
  "label": "Settings",
  "identifier": "Settings",
  "bounds": [917, 1167, 1122, 1439]
}
```

- `role`: `Button`, `StaticText`, `TextField`, `Switch`, …
- `label`: what VoiceOver reads.
- `identifier`: the app’s `accessibilityIdentifier`.
- `value`: a text field’s content, a switch’s `0` or `1`, a slider’s text.
- `bounds`: `[left, top, right, bottom]`, the frame in points times the screenshot’s `scale`.

The first call compiles the helper and takes a few seconds; later calls take about 0.25 s. The helper only reads: it installs nothing in the simulator, needs no macOS permission and leaves no process running.

For more information, see [`ui-tree`](https://karagozmcp.com/docs/commands/ui-tree/#on-an-ios-simulator).

## 4. Tap, type and press keys

`karagoz tap --text <label>` taps the node whose `label` or `value` equals the label, and `--id` the one whose `identifier` equals it. Both match the whole string, case-sensitive. `karagoz tap <x> <y>` takes the same pixels as the tree’s `bounds`.

```json
{
  "device": "27024DC1-EDB0-4BF2-8010-08FE3936BAB6",
  "x": 603,
  "y": 1015,
  "element": {
    "role": "Button",
    "label": "Tap me 0",
    "identifier": "tap-button",
    "bounds": [48, 937, 1158, 1093]
  }
}
```

Karagöz taps the node’s center like a finger, so whatever covers it gets the tap. There is no keyboard check on a simulator.

`karagoz text <text>` types any Unicode text exactly, at the cursor. iOS applies no auto-capitalization, smart quotes or smart dashes to it. With no focused field, `text` types nothing and still exits `0`.

```json
{
  "device": "27024DC1-EDB0-4BF2-8010-08FE3936BAB6",
  "text": "çğş it's -- ok"
}
```

`karagoz key HOME` presses the Home button. Only these names have a key on the simulator: `HOME`, `POWER`, `VOLUME_UP`, `VOLUME_DOWN`, and the hardware keyboard keys (letters, digits, `ENTER`, `DEL`, `TAB`, `ESCAPE`, `DPAD_*`, `F1`-`F24` and others). `BACK` has none: tap the app’s back button or swipe from the left edge.

On a Mac that never had Xcode 27, the first input command builds Karagöz’s runner and installs it on the simulator. That call takes about half a minute, later ones under a second.

For more information, see [`tap`](https://karagozmcp.com/docs/commands/tap/#on-an-ios-simulator), [`text`](https://karagozmcp.com/docs/commands/text/#on-an-ios-simulator) and [`key`](https://karagozmcp.com/docs/commands/key/#on-an-ios-simulator).

## 5. Take a screenshot

`karagoz screenshot` saves the screen as a PNG, exactly as simctl wrote it. Without `--out` it goes to a new file under the temp directory:

```json
{
  "path": "/var/folders/.../T/karagoz/27024DC1-EDB0-4BF2-8010-08FE3936BAB6-20261012T182033769Z.png",
  "device": "27024DC1-EDB0-4BF2-8010-08FE3936BAB6",
  "pixels": { "width": 1206, "height": 2622 },
  "logical": { "width": 402, "height": 874 },
  "scale": 3,
  "safeArea": null,
  "rotation": 0
}
```

Its pixels share one space with the tree’s `bounds`. `safeArea` is `null` on iOS: only the app itself can read its safe area.

For more information, see [`screenshot`](https://karagozmcp.com/docs/commands/screenshot/).

## 6. Install, launch and open a URL

- `karagoz install <path>` takes a `.app` bundle directory or an `.ipa` built for the simulator, and runs `simctl install`. A build for a physical iPhone fails with `INSTALL_FAILED`, `reason` `IXUserPresentableErrorDomain:4`.
- `karagoz launch <bundle id>`, such as `com.apple.Preferences`, runs `simctl launch`. It returns when the app’s process starts, before the app is in front: a `ui-tree` read right away can still show the previous screen.
- `karagoz open-url <url>` runs `simctl openurl`. For an app’s own scheme, iOS first asks `Open in “<app>”?`. The app gets the URL only after you tap Open: `karagoz tap --text Open`.

An install prints the simulator and the app’s path:

```json
{
  "device": "2EC769C1-2EF2-47EB-A441-E6843968F039",
  "path": "/Users/me/Build/Products/Debug-iphonesimulator/Probe.app"
}
```

For more information, see [`install`](https://karagozmcp.com/docs/commands/install/#on-an-ios-simulator), [`launch`](https://karagozmcp.com/docs/commands/launch/#on-an-ios-simulator) and [`open-url`](https://karagozmcp.com/docs/commands/open-url/#on-an-ios-simulator).

## When it fails

- [`SIMCTL_NOT_FOUND`](https://karagozmcp.com/docs/error-codes/#simctl-not-found): no `simctl` found. Xcode is missing or was never opened, or `DEVELOPER_DIR` points somewhere without one.

- [`HELPER_FAILED`](https://karagozmcp.com/docs/error-codes/#helper-failed):

  - for `ui-tree`, this Mac cannot read iOS trees: no Xcode selected, no `swiftc` at the selected Xcode’s toolchain path, a failed compile, a crashed helper, or an Xcode that changed a private interface Karagöz uses (update Karagöz);
  - for `text`, the automation session was not granted or the typing failed;
  - on a Mac that never had Xcode 27, the runner’s build or start failed, with the log path.

- [`NOT_SUPPORTED`](https://karagozmcp.com/docs/error-codes/#not-supported):

  - input with Xcode 26 or older selected, on a Mac that once had Xcode 27: `'tap' on iOS simulators needs Xcode 27 or later`;
  - `text` on a simulator older than iOS 27, with Xcode 27 or newer;
  - `open-url --app`: `an iOS simulator opens a URL only in the app the system picks; run open-url without --app`.

- [`AUTOMATION_BUSY`](https://karagozmcp.com/docs/error-codes/#automation-busy): a UI test running on the same simulator makes `text` fail.

- [`CAPTURE_FAILED`](https://karagozmcp.com/docs/error-codes/#capture-failed): the screen could not be read, with the reason in the message. One reason has a fix: an app opened while the simulator’s app accessibility setting was off reads as an empty root. An Xcode UI test turns that setting off when it ends. Karagöz turns it back on, and its message says to restart the app: [`terminate`](https://karagozmcp.com/docs/commands/terminate/) it, launch it, and read again.

- [`DEVICE_NOT_READY`](https://karagozmcp.com/docs/error-codes/#device-not-ready): the simulator is `Booting` or `Shutting Down`, or its input service did not answer within 4 s right after a boot. On a Mac that never had Xcode 27, also a runner that did not start within 60 s, or a port another process took.

## Related pages

- [Requirements](https://karagozmcp.com/docs/requirements/): what the simulator commands need, and how Karagöz finds `simctl`.
- [`devices`](https://karagozmcp.com/docs/commands/devices/): booted simulators next to Android devices.
- [`ui-tree`](https://karagozmcp.com/docs/commands/ui-tree/), [`tap`](https://karagozmcp.com/docs/commands/tap/), [`text`](https://karagozmcp.com/docs/commands/text/) and [`key`](https://karagozmcp.com/docs/commands/key/): reading the screen and input, with an “On an iOS simulator” section each.
- [`screenshot`](https://karagozmcp.com/docs/commands/screenshot/), [`install`](https://karagozmcp.com/docs/commands/install/), [`launch`](https://karagozmcp.com/docs/commands/launch/) and [`open-url`](https://karagozmcp.com/docs/commands/open-url/): the PNG and the app commands.
- [Output](https://karagozmcp.com/docs/output/#coordinates): the coordinate space the tree, `tap` and the screenshot share.
