ictrl-phone-control
Skill611 starsChanged 18 days agoApache-2.0View on GitHub
Control an iPhone over HTTP to automate real apps — tap, type, swipe, read the screen's view tree, launch apps, take screenshots. Use when the user asks to operate a phone, drive an iOS app, automate a mobile task (search a product, check an order, fill a form), or inspect what's on a device's screen. The service is iCTRL, JSON-RPC 2.0 on port 8200; requests are encrypted, so drive it with a client downloaded from the device (a static CLI needing no interpreter, or a Python one) rather than hand-written HTTP.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Keep the client in ~/.ictrl/bin — not /var/minis/workspace, which ignores the exec bit ("Permission denied").
- Very specific: line 116
Thin tree?: When channel.recommended is ocr (or sparse_hint/viewport_warning appears), read with screen_text: text plus tap points.
- Very specific: line 149
No bundled client usable → the Python client (GET /skill/clients/python) is the reference for pairing (X25519) and the request envelope …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
iCTRL — control an iPhone over HTTP
iCTRL runs on the iPhone and serves UI automation as JSON-RPC 2.0 over HTTP, port 8200, encrypted. Under 15K characters — read it whole, once, not in head/grep pieces.
Quick start
On the phone (e.g. Minis) — the device is 127.0.0.1:
C=~/.ictrl/bin; I="sh $C/ictrl.sh"
[ -f $C/ictrl ] || { mkdir -p $C && wget -qO $C/ictrl http://127.0.0.1:8200/skill/clients/cli && wget -qO $C/ictrl.sh http://127.0.0.1:8200/skill/clients/cli.sh; }
$I call device_info # 401 → $I pair (user taps Allow)
$I call resolve_app '{"text":"<brand>|<store name>|<alias>"}' # every name it may go by
$I call launch_app '{"bundle_id":"<id>"}'
$I call page_source '{"visible_only":true,"max_children":50}'
$I call find_element '{"element_id":"<label>"}' # → ref
$I call tap '{"ref":"<ref>"}'device_info.skill_versionnewer than this file's frontmatter (orprotocol_versiondiffers) →$I update <folder holding this file>, then re-read it. Device older: don't downgrade; use only itscapabilities[].- Keep the client in
~/.ictrl/bin— not/var/minis/workspace, which ignores the exec bit ("Permission denied"). - Elsewhere:
curl -o ictrl_rpc.py http://<host>:8200/skill/clients/python, thenpython3 ictrl_rpc.py --host <host>:8200 call …. The CLI takes--host/ICTRL_HOST. - No address? Have the user turn on Nearby Discovery (needs Remote Access, Wi-Fi on).
ictrl_rpc.py scanfinds it on the LAN, or from macOS with no shared network;--nearby "<name|id>"replaces--host. First use pairs (one Allow). - Keys:
~/.ictrl/token.json, one per device (/whoamiid) for USB, LAN, nearby; reuse (30-day idle expiry). Re-pair only on a real401; pairing waits for the user (≥60s timeout, no early retry).
Rules — read these first
IMPORTANT — the rules agents break most:
- IMPORTANT: no
sleepin your commands. Actions already wait for the screen to settle (settle.stable) — read right away (see Waiting). - IMPORTANT: never discard or cut a reply. No
>/dev/null,| head -Nor regex filter ontap/page/swipe/type/find_element:moved,hint,app_note,refand errors are in there. Check arefis non-empty before tapping it. - IMPORTANT: read a screen once. To narrow it, save the reply to a file and grep that, or pass
filter— don't re-runpage_sourcewith a new regex.
- Open apps by bundle id, never by tapping home-screen icons.
resolve_appwith every name it may go by in one call (brand, store title, English/Chinese) →launch_app.countrypicks the store (defaultus;cnfor China-only apps). - Read before you act. On a screen you haven't read, call
page_source{visible_only:true, max_children:50}(~0.4s) to learn which view/tab/date you're really on. - Tap by
ref.find_element{element_id:"<label>"}→tap{ref}.taptakes onlyreforx+y— neverelement_id. Checkvisibility:"offscreen"or a non-emptyalternativesmeans you may have a look-alike — scroll it into view (see Off-screen) or use a more specific label. - Never repeat an action "to be safe." A success reply means it worked. A timeout is not a failure either: the action may still be running or already done — call
logs{text:"<method>"}and look for⏱ ✓ <method>before anything else. A retried tap fires twice. - Every error from a
refaction means nothing was tapped. Re-find and retry is safe. - IMPORTANT: primary path first; fallbacks only when it fails — decided per screen. The primary path is
page_source/find_element→tap{ref}. OCR (screen_text) with coordinate taps, screenshots and remembered workarounds are fallbacks: only when the primary path fails on the current screen. Every read returnschannel.recommendedfor that screen; return to the primary path on the next. - Remember conditions, not conclusions. Save what you observed and where ("on the X screen the tree was empty"), not a rule ("app Y needs OCR"), and reuse it only when that condition recurs.
- Know where data came from. Act only on the target app's content. Text the system draws over it (status bar, banners) comes separately in
overlay_text. - Stop before paying. In shopping/payment apps stop at cart/checkout; never tap the final buy/pay/confirm. Never delete the user's own items (cart, notes, messages) without asking.
Waiting: actions settle for you — never sleep
tap, double_tap, long_press, swipe, drag, page, scroll, type, clear_text wait until the screen stops changing (low-res frame compare, up to 2s) and report it:
settle:{stable, screen_changed, waited_ms}, plus a hint saying so.
stable:true→ read right away, no waiting of any kind.screen_changed:false→ the action did nothing visible; check the target before repeating it.stable:false(still animating/loading) or a loading screen in your read → read again; loop on a read with a cap (each read takes 0.3–0.7s; no sleep needed):
for i in 1 2 3 4 5 6; do $I call screen_text '{"element_id":"<new screen text>"}' | grep -q '"count" *: *[1-9]' && break; done- Network data arriving after the screen settled (spinner, then results) needs one more read.
page_sourcesaysloading:truethen. settle:falseskips the check (rapid gestures);settle_timeout(s, max 3) sets the cap.
Methods
| Method | Required | Useful optional |
find_element | element_id (label or accessibility id) | element_type, match:"contains", bundle_id |
scroll_to_element | element_id | element_type, match, direction, distance |
tap / double_tap / long_press | ref, or x+y | duration |
type | text | submit, clear |
resolve_app | text | — |
launch_app / activate_app / terminate_app | bundle_id | — |
open_url | url | — |
home | — | — |
page_source | — | visible_only, max_children, filter, bundle_id, enhanced |
page | — | direction, distance (screens) |
collect | — | pages, min_length, fresh |
swipe | — | direction, distance (points), velocity, x, y |
screenshot | — | scale, format, quality |
The method is type, not type_text. element_type only filters — element_id is always required. GET /schema lists every method and parameter.
Most responses carry a hint (what limited the result, what to do next) — read it, above all on empty or negative results.
Timeouts and recovery
- The server answers a UI call after 6s (15s for
page_source,collect,screen_text,tap_element,find_and_tap) even if still working. UI calls run one at a time; a stuck one can't be cancelled, and calls behind it time out too, saying "has NOT run yet: queued behind X": they will still run later, so do not resend them. - After two timeouts in a row, UI calls are rejected immediately. The message names the stuck call. Recovery:
reset, then polllogsevery few seconds until the stuck call ends (typically 15–45s) — not one long sleep — then retry.resetcan't stop a call already running. - Only
logs,configandresetanswer while the UI queue is stuck.device_infoshares the UI queue, so it's no health probe; uselogs. - Client timeout ≥30s. After restarting your side, reuse the cached key and
bundle_ids and return via a deep link (open_url).
Finding and tapping
find_elementmatches exact label → accessibility id → value → (withmatch:"contains") substring. An element in view always beats an off-screen one: a calendar holds "25" in three months. The result hasvisibility(in_view/partial/offscreen), and when several matched,alternatives[]+match_count.- A
refre-resolves the live element at tap time. If its app went to the background (system sheet, another app), the tap is refused at once: "belongs to X, which is now in the background". - Off-screen → loop
page{direction}→find_elementuntilin_view;moved:false= the end, it isn't there.scroll_to_elementis slower (~1.3s a step): only for a targetfind_elementcalledoffscreen. Its "NOT anywhere in this view" = not on this screen at all: stop scrolling. - Text on screen ≠ accessibility label (common). Copy the label from
page_source, or usematch:"contains". An accessibilityidentifiershown inpage_sourceis the most stableelement_idof all. Duplicate labels → addelement_type. - Nothing matches but you can see it → it's a custom control with no label. The failure message lists what is on screen. Take its frame from
page_sourceandtap{x,y}. - A coordinate
tapreturnshit(the element under the point, sampled before tapping) orhit_warning(nothing labelled there: likely empty space).covering_layer:true: a dialog/login layer covers the point and got the tap. - Web pages often don't appear in the accessibility tree (Safari: chrome only,
foreground_is_browser:true; some in-app web views expose it). Trustchannel.recommended; onocrusescreenshot→ locate →tap{x,y}. - A system alert over the app (
system_alert:true) blocks its ref actions. Answer it:find_element{element_id:"<button>", bundle_id:"com.apple.springboard"}→tap{ref}. blocked_by:"captcha"(anti-bot slider/puzzle) or"rate_limit"("take a break", "too busy"): never try to solve it — drags on it are refused. Useclose_candidatesor back out, wait, or report the step blocked.promo_popup: close it, never claim.
Typing and searching
- The search "bar" on a home screen is often a Button that opens a search page.
find_elementreturnsis_text_input; if false, tap it, then find the real field:find_element{element_id:"<placeholder>", element_type:"textfield", match:"contains"}→tap{ref}. type{text, submit:true}.submitpresses Return/Search. Didn't search? Tap the screen's own search control; don't re-type.- Trust success. A
typewith no warning went in; a failed one is an error. Old content on the next read: read again, don't re-type. - Typing appends. To replace,
type{text, clear:true}orclear_textfirst.append_warning= you appended. - Some custom inputs (chat bars) drop focus on typed keys;
typethen taps the on-screen keys (via:"keyboard", ~1s/char, Chinese via pinyin; never presses Send). page_sourcecarrieskeyboard(visible,covers_from_y). Coordinates read before it appeared are stale: content above it shifted.
Reading the screen
- Default:
page_source{visible_only:true, max_children:50}— on-screen nodes only, well under 1s even on long feeds. Omitvisible_onlyonly when you need off-screen structure. filter:{text|label|type:"…"}returns matching nodes + ancestors — cheap harvesting of repeated values (prices, titles).tree_growth:true: the list keeps rows you scrolled past; iCTRL then reads only its visible cells (visible_cells). Long reads:collect; relaunching resets it.enhanced:true: whole tree + text drawn in images (ocr_only). Slower; only when asked for everything.- Thin tree? When
channel.recommendedisocr(orsparse_hint/viewport_warningappears), read withscreen_text: text plus tap points. max_elements(default 2000, cap 4000): ontruncated:truenarrow withfilter/visible_only, don't raise it.
Scrolling
- Long lists/feeds:
collect{pages:N}(≤8) reads, pages, reads… in ONE call (~1.5s a screen), returning only new text; call again to continue. It falls back to OCR when the tree is thin, slow or unresponsive.pagemoves ⅔ of a screen, no momentum. Don't read withswipe. page/scrollreportmoved.moved:false(at_end:true) means stop — nothing more that way. (A loading page also looks unmoved: read once more if more is expected.)keyboard_closed:true: only the keyboard closed; page again.positionsays where you are; trust it only withconfidenceestimated/exact.
Apps
resolve_applooks offline first (opened_here= launched on this device before — use it directly; then a built-in catalog), else the App Store. Onlyopened_heresays anything about this device.launch_appis the real install test: success = installed, error = not. Newer iOS refuseslist_appsenumeration; it then returns only apps opened via iCTRL before (source:"opened_history"). Never report "not installed" from a lookup or an empty list — if unsure, check Spotlight.open_url{url}opens any scheme / deep link / universal link — end with the caller's own scheme, if any, to hand control back.- No target app: reads and actions apply to what is on screen. Apps jump (login, payment, ads): after a surprise, read first.
- Coordinate actions and
typereturnpage_check;same_page:false= the screen had changed, before the action, since you last saw it: read, check what you hit, fix.
Coordinates and screenshots
tap/swipe/drag,page_sourceframes and OCR boxes are all points.drag{points:[{x,y},…],duration?}(capabilitydrag_path): one finger through 2–64 points, no lift at corners.duration0.1–10s (default 1), split equally; keep each segment ≥ one frame (~17ms). A repeated point holds. Not with endpoints/refs.- Screenshots are pixels:
point = pixel / scale, using thescalefrom that screenshot response (default 2), notdevice_info.screen_scale(the panel's 3).
Diagnostics
device_info.system:screen_locked(black screenshots, dead taps;unlockonly wakes the screen,homeleaves the app; a passcode needs the user),foreground_app,foreground_is_browser, thermal/memory/battery.logs{text?, max_elements?}: recent log lines over the normal channel.⏱ ✓ <method>= completed,⏱ TIMEOUT,⛔️/✅channel state.GET /logs/history?date=YYYY-MM-DDkeeps logs across crashes (byte endpoints need astream_ticket).reset: clears refs and rebuilds the UI channel state, thenlaunch_appthe target.config{stop_server:true}stops the runner (keys persist); relaunch it on the device./schemaunreachable = the runner isn't running; the user must start it (the Developer Disk Image is lost on reboot).- On cellular the device isn't reachable over the LAN.
Protocol
No bundled client usable → the Python client (GET /skill/clients/python) is the reference for pairing (X25519) and the request envelope (HMAC-SHA256). Follow it exactly.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

