iPhone-use
Browse docs
On this page

CLI workflow

Discover, connect, observe and act with explicit execution facts.

Discover and connect

First complete device preparation. Replace device and session placeholders with the IDs actually returned. Read each result before continuing.

iphone-use devices
export IOS_UDID='YOUR_DEVICE_ID'
iphone-use connect --device "$IOS_UDID" --mode standard
export SESSION='SESSION_FROM_CONNECT'
iphone-use --session "$SESSION" apps --query Settings
iphone-use --session "$SESSION" open com.apple.Preferences
iphone-use --session "$SESSION" observe

devices lists CoreDevice-known devices, not guaranteed ready sessions. Check result.controlAvailable=true after connecting. apps --query searches installed names and bundle IDs. open verifies installation, then activates or launches the app; it does not install or restart it. connect --reuse can reuse a healthy existing session; preserve it unless asked to disconnect.

Read the observation

Standard mode returns the Apple PNG path, observation ID and screen geometry. Read the actual image. Coordinates are screen points, not image pixels: convert using this observation’s image and screen dimensions. Runner can also expose accessibility elements such as o1:e10; inspect searches only that cached snapshot. After each action, use the new observation and fresh references.

Use current observations

These are separate syntax examples, not a script to run together. Replace every uppercase placeholder with values from the screen you just read.

iphone-use --session "$SESSION" tap OBSERVATION_ID --x POINT_X --y POINT_Y --observe
iphone-use --session "$SESSION" swipe OBSERVATION_ID --from-x START_X --from-y START_Y --to-x END_X --to-y END_Y --observe

Text input requires confirmed focus. Standard mode binds type to an observation and retains its native insert/replace/append contract. Select the complete input field with --field-rect; omitting it protects the whole screen. Unicode uses clipboard-backed paste and may require iOS permission. Confirm the visible result before finishing the clipboard transaction with text-finish. Never replay unknown input. See the standard action contract and installed help.

--observe returns separate action and observation receipts. Standard mode waits within a bounded post-action stability budget. A valid screenshot may still carry a stability timeout; neither a stable image nor a successful command proves the business result.

Runner text: focus, select, clear, insert

In CLI 0.4.0, Runner type inserts literal text once at the existing focused caret or selection. It does not focus, clear, replace or move the caret. Runner --mode replace and --mode append reject before dispatch. This replacement workflow is conditional: read each result and screenshot before continuing. Replace CURRENT_INPUT_REF at every step with the same intended field’s reference from the latest observation.

1. Focus the intended input and confirm focus.

iphone-use --session "$SESSION" focus CURRENT_INPUT_REF --observe

2. Request Select All, then visually verify the intended selection. A key acknowledgement alone does not establish the selection.

iphone-use --session "$SESSION" press CURRENT_INPUT_REF --key select-all --observe

3. Clear the verified selection and confirm that the field is empty. clear sends one Delete; it does not select all automatically. It requires a focused, non-secure field with a readable value before dispatch.

iphone-use --session "$SESSION" clear CURRENT_INPUT_REF --observe

4. Only after confirming the empty field, insert the intended text once and verify the entire visible result.

iphone-use --session "$SESSION" type CURRENT_INPUT_REF --text "Your intended text" --observe

To append, focus, request press CURRENT_INPUT_REF --key end --observe, then verify that the original value is unchanged and the caret is at the intended end before inserting only the suffix. End-key device acceptance is not established by the 0.4.0 release. There is no general selected-range API: if selection or caret placement cannot be verified, stop instead of guessing. Return/Tab can submit or move focus; observe the resulting page. See the Runner action contract for text limits and verification rules.

Execution outcomes

completed
Execution completed. Read action-specific verification and the screen to establish the intended result.
not_dispatched
Input was not sent. Follow the error and requiresObservation to correct the request or refresh references.
unknown
Input may have happened. Read the attached observation or acquire one, then inspect the result before deciding the next action. Do not replay blindly or restart the workflow.

For Runner focus/type/clear, inputAction.eventAttempted and eventAcknowledged describe execution; inputAction.verification is separately confirmed, unconfirmed, unavailable or not_requested. An acknowledged event can have unconfirmed verification. A verified no-op can have both event flags false. Preserve the action receipt if observation fails; recover the observation without repeating input.

Screen checks

Actions compare current screen information against their original observation before dispatch. If the scene changes, read the returned new image and choose again. Video exclusions and caret locations must come from the current screen; do not broaden tolerances to force input. Standard screenshots do not require a persistent media stream. Preview and recording share the session’s owned stream; input still checks for competing clients. For native_media_busy, ask the owner to end the competing client’s control session, then follow recovery without closing foreign sessions.

Local preview and access

After connecting, enable preview once. This returns a local URL without opening a browser:

iphone-use --session "$SESSION" preview --no-open

Open the URL in one tab and reuse it. Without --no-open, preview opens the browser. Plain connect does not open one. The viewer is for watching, not a replacement for reading observation PNGs, and viewer traffic does not extend the session’s idle timeout.

The /v/<token>/ URL is stable for the same device, configuration directory and port. Disconnect clears frames and the source, but does not revoke access to future explicitly enabled previews. Treat the URL as a private local credential; do not publish it. After reconnecting, explicitly enable preview again to reuse the same tab.

To stop the current preview without disconnecting control or stopping recording:

iphone-use --session "$SESSION" preview --stop

To revoke a stable URL, use the hardware UDID and actual preview port (8765 by default), with the same configuration directory. Then explicitly stop/start preview and open the new URL in the existing tab:

iphone-use preview-revoke --device "$IOS_UDID" --port 8765

preview-service-stop --port PORT affects every viewer on that port, not just one session; it does not disconnect control or stop recording. An ok receipt only accepts the request; exited: true with state: stopped confirms exit. Do not terminate unrelated processes to reclaim a port.

Finish the session

Finish or stop your recording, then disconnect the session you created when the task is complete. Preserve a reused session unless the user requested disconnection.

iphone-use --session "$SESSION" disconnect

Disconnection clears preview frames but does not revoke its stable URL; use the revocation command above when access must be withdrawn.