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
Section titled “1. Before you start”- Xcode, opened once. The Command Line Tools alone have no
simctl, and noswiftcfor the helper. - A booted simulator:
xcrun simctl boot <name>. - For input (
tap,long-press,double-tap,swipe,textandkey): Xcode 27 or newer. On a Mac that never had Xcode 27, input goes through Karagöz’s runner instead. - For
textwith Xcode 27 or newer: a simulator on iOS 27 or newer. - Karagöz: Install.
2. Find the simulator
Section titled “2. Find the simulator”karagoz devicesFound 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.exit 0Only 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.
3. Read the screen
Section titled “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):
{ "device": "27024DC1-EDB0-4BF2-8010-08FE3936BAB6", "rotation": 0, "root": { "role": "Application", "label": " ", "bounds": [0, 0, 1206, 2622], "children": […] }}A node from the same tree:
{ "role": "Button", "label": "Settings", "identifier": "Settings", "bounds": [917, 1167, 1122, 1439]}role:Button,StaticText,TextField,Switch, …label: what VoiceOver reads.identifier: the app’saccessibilityIdentifier.value: a text field’s content, a switch’s0or1, a slider’s text.bounds:[left, top, right, bottom], the frame in points times the screenshot’sscale.
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.
4. Tap, type and press keys
Section titled “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.
{ "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.
{ "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, text and key.
5. Take a screenshot
Section titled “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:
{ "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.
6. Install, launch and open a URL
Section titled “6. Install, launch and open a URL”karagoz install <path>takes a.appbundle directory or an.ipabuilt for the simulator, and runssimctl install. A build for a physical iPhone fails withINSTALL_FAILED,reasonIXUserPresentableErrorDomain:4.karagoz launch <bundle id>, such ascom.apple.Preferences, runssimctl launch. It returns when the app’s process starts, before the app is in front: aui-treeread right away can still show the previous screen.karagoz open-url <url>runssimctl openurl. For an app’s own scheme, iOS first asksOpen 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:
{ "device": "2EC769C1-2EF2-47EB-A441-E6843968F039", "path": "/Users/me/Build/Products/Debug-iphonesimulator/Probe.app"}For more information, see install, launch and open-url.
When it fails
Section titled “When it fails”SIMCTL_NOT_FOUND: nosimctlfound. Xcode is missing or was never opened, orDEVELOPER_DIRpoints somewhere without one.HELPER_FAILED:- for
ui-tree, this Mac cannot read iOS trees: no Xcode selected, noswiftcat 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.
- for
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; texton 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.
- input with Xcode 26 or older selected, on a Mac that once had Xcode 27:
AUTOMATION_BUSY: a UI test running on the same simulator makestextfail.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:terminateit, launch it, and read again.DEVICE_NOT_READY: the simulator isBootingorShutting 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
Section titled “Related pages”- Requirements: what the simulator commands need, and how Karagöz finds
simctl. devices: booted simulators next to Android devices.ui-tree,tap,textandkey: reading the screen and input, with an “On an iOS simulator” section each.screenshot,install,launchandopen-url: the PNG and the app commands.- Output: the coordinate space the tree,
tapand the screenshot share.