Documentation

Build with ketec.

Start with the quick start, then browse the script modules and the HTTP API. Complete references are linked at the end of each section.

terminal
$ curl http://<iphone-ip>:9800/api/status
# app and iOS version, device model, run mode, recording state
$ curl "http://<iphone-ip>:9800/api/control/click?x=540&y=1200"
# tapped at 540, 1200
$ curl -o screen.jpg http://<iphone-ip>:9800/api/screenshot
# full-resolution JPEG saved

Quick start

Five steps from a fresh install to your first automated tap.

  1. Install the app

    Join through TestFlight on an iPhone with iOS 15 or later, then open ketec once so it can start its local service.

  2. Choose a run mode

    In Settings, pick Agent or HID. The Status tab shows whether the channel is ready.

  3. Write a script

    Create scripts/main.js, scripts/main.lua or scripts/main.py. The examples below do the same thing in each language.

  4. Run it

    Install the package from the Packages tab, or post a JavaScript snippet to the HTTP API.

  5. Stop cleanly

    Register a stop callback. It receives success, error or stopped, so you can save state before the run ends.

// scripts/main.js
setStopCallback((status) => logi("finished: " + status));

logi("Hello from ketec on iOS " + device.getOSVersion());
system.startApp("com.apple.Preferences");
sleep(1500);

// Find "General" with on-device OCR and tap it
const hits = paddleOcr.findTextAbs("screen", ["General"]);
if (hits.length > 0) {
  action.click(hits[0].centerX, hits[0].centerY);
}
-- scripts/main.lua
SetStopCallback(function(status) logi("finished: " .. status) end)

logi("Hello from ketec on iOS " .. device.getOSVersion())
system.startApp("com.apple.Preferences")
sleep(1500)

-- Find "General" with on-device OCR and tap it
local hits = paddleOcr.findTextAbs("screen", {"General"})
if #hits > 0 then
  action.click(hits[1].centerX, hits[1].centerY)
end
# scripts/main.py
import time
from ketec import g, device, system, paddleocr, action

g.setStopCallback(lambda status: print("finished:", status))

print("Hello from ketec on iOS", device.getOSVersion())
system.startApp("com.apple.Preferences")
time.sleep(1.5)

# Find "General" with on-device OCR and tap it
hits = paddleocr.findTextAbs("screen", ["General"])
if hits:
    action.click(hits[0].centerX, hits[0].centerY)

Run a one-off snippet over the network (JavaScript only):

terminal
curl -X POST http://<iphone-ip>:9800/api/runScript \
     -H "Content-Type: application/json" \
     -d '{"script":"action.click(540, 1200); device.getOSVersion()"}'

Run modes

Both modes run the same scripts. They differ in how input reaches the system and what is available.

Agent

touches go through the system automation service. Node selectors, the UI tree, multi-finger gestures and W3C Actions are available. Requires a one-time activation from a computer over USB with ketec Activator (see Download).

HID

an ESP32-S3 accessory on USB sends real mouse and keyboard input. Use the hid module or the /api/hid endpoints. The UI tree is not used in this mode; find targets with images and OCR. Two pointer modes cover older and newer iOS versions.

Script packages

A package is a folder with an entry script plus any resources it needs. ketec picks the engine from the entry file.

scripts/main.js · scripts/main.lua · scripts/main.pyEntry script: JavaScript, Lua or Python
file.readResFile() · image.readImage()Images, models, fonts and other files
ui.show()Optional web settings page for the UI tab

Settings saved with the config module are kept separately from the app’s own settings, persist between runs and keep their types: store 5 and you read back 5.

Languages

Module names and arguments are identical across languages. Only the syntax changes.

JavaScript

Modules are globals: action.click(x, y). Logging with logi / logd / logw / loge or console. Timers with setTimeout and setInterval.

Lua 5.4

Modules are global tables; objects use colon calls: sel:getOneNodeInfo(3000). Globals such as sleep, logi and SetStopCallback.

Python 3.14

Import what you need: from ketec import action, image, g. Results support both r.name and r["name"]. Global helpers live in g.

Script API by module

A map of the modules available to scripts, grouped by what they do. Function names are the same in all three languages.

Core

globalPython: g

Sleep, timing, logging, stop and exception callbacks, touch mode and CPU throttling.

sleeptimeexitlogilogwlogesetStopCallbacksetExceptionCallbackrestartScripttakeMeToFrontsetAgentTouchMode

action

Taps, swipes, curves, text input, buttons, key combos and multi-finger builders.

clickdoubleClickclickRandomswipeswipeCurvepressAndSwipeinputinputSimplebackspaceenterhomeScreenpressButtonsendKeyw3cActionscreateBuildersetJitterValue

node

Find controls in the UI tree and act on them. Agent mode.

createNodeSelectorlabellabelMatchtitleidentifiertypevaluexpathgetOneNodeInfogetNodeInfoclickCenterscrollToVisibleparentchildreleaseNode

image

Capture the screen, find images and colors, crop, rotate, binarize and scan codes.

captureScreenreadImagefindImagefindImageExfindColorfindMultiColorcountColorcmpColorpixelcliprotateImagebinaryzationscanCodesaveTorelease

device

Battery, storage, screen metrics, brightness, volume, orientation and identifiers.

getBatteryInfogetStorageSpacegetDeviceNamegetDeviceModelgetOSVersiongetScreenRealSizegetScreenScalegetOrientationgetScreenBrightnesssetVolumegetLanIpvibrate

system

Apps, URLs, clipboard, lock state, memory and CPU usage, notifications.

startAppstopAppactivateAppactivateAppInfogetInstalledAppListopenURLsetClipboardgetClipboardisLockedlockunlockgetMemoryInfogetCpuUsagenotify

ime

Type, paste, clear and read text through the ketec keyboard.

isOkinputpasteclearTextgetTextpressEnterpressDeldismissswitchKeyboard

ui

Show the settings page, toasts and dialogs; talk to the page from the script.

showhideshowToastconfirmconfirmInputalertonEventcalleval

pip

Floating picture-in-picture window with log, keep-alive and custom text modes.

isPipActiveswitchToLogModeswitchToKeepAliveModeswitchToCustomModesetCustomTextsetPositioncloseWindow

hotUpdatePython: hotupdate

Check for, download and install new versions of a script package.

checkUpdatedownloadAndInstallgetCurrentVersion

Hardware

hid

Hardware mouse and keyboard through the ESP32-S3 accessory, plus accessory status.

clickdoubleClickmovemouseDownmouseUpswipeswipeCurveinputinputSimplesendKeypressButtonopenAppcloseAppopenURLrecenthomeScreenisUSBConnectedgetDeviceVersionresetPositionrestartDevice

Network & data

httpPython: requests

GET, POST, JSON, file downloads and WebSocket connections.

httpGethttpPostpostJSONrequestdownloadFilenewWebsocket

cloud

Connect to your cloud control server, report data and receive events.

connectisConnecteddisconnectreportonEvent

mysql

Connect to MySQL, run queries and statements, use transactions.

connectqueryexecutebeginTransactioncommitrollbackdisconnect

sqlite

Local SQLite databases with queries and transactions.

openqueryexecutebeginTransactioncommitrollbackclose

file

Read, write and append files, line helpers, directories and package resources.

readFilewriteFileappendLinereadLinereadAllLinesdeleteLinelistDirmkdirsexistscopyfileMD5readResFilegetResFile

zipFile

List, create and extract ZIP archives.

zipunzipgetFileListisZip

plist

Read and edit property list files.

readwritegetsetremove

config

Script settings that persist between runs and keep their types.

getsetremoveallsetAll

cryptoUtils

AES and RSA encryption, MD5, SHA-1 and SHA-256.

encryptWithAES_ECBdecryptWithAES_ECBencryptWithRSAdecryptWithRSAmd5sha1sha256

Vision & AI

paddleOcrPython: paddleocr

On-device PP-OCR for Chinese, English, Japanese, Korean and digits.

recognizeAbsfindTextAbsloadModelsetMaxSideLenfree

appleOcrPython: appleocr

The system Vision text recognizer.

recognizeAbsrecognizeNumbersAbsfindTextAbs

tomatoOcrPython: tomatoocr

Bundled open-model OCR with tap-point helpers. No license key.

ocrImagefindTapPointfindTapPointssetRecTypesetReturnTyperelease

dotOcrPython: dotocr

Dot-matrix OCR with fonts you load yourself.

loadFontrecognizeAbsfindTextAbsfreefreeAll

yolo

Run your own YOLO detection models on the screen or a region.

loaddetectAbsfreefreeAll

yoloClsPython: yolocls

Run YOLO classification models.

loadclassifyclassifyRegionfreefreeAll

cvPython: cv2

Around 140 OpenCV functions on Mat objects. In Python, use cv2 directly.

imreadcvtColorthresholdCannyfindContoursmatchTemplateresizeGaussianBlurinRangeORBSIFTdetectQRCode

ai

Configure LLM providers, then ask, judge, extract and chat.

setProvideraskjudgeextractchatparseJson

tts

Text to speech with system voices.

speakwaitEndstopisSpeakingsetVoicegetAvailableVoices

Runtime & utilities

logger

Log levels, log files, file size and rotation.

debuginfowarnerrorsetLoggerLevelsetLogToFilesetMaxLogFileSize

media

Save to the photo library, clean up photos and videos, play audio.

saveImageToAlbumsaveVideoToAlbumPathdeleteAllPhotosdeleteAllVideosplayMp3stopMp3

threadPython: sharedState

Run functions in parallel threads; share values with sharedState.

runstopAllsharedState.setgetwithBatchclear

utils

Time formatting, random numbers, UUIDs, Base64 and hex helpers.

timeFormatrandomrandomUUIDbase64Encodedbase64DecodedhexString

Plus node methods such as label, labelMatch, type, xpath, clickCenter, scrollToVisible, parent and child on every selector result.

Full script API reference · script-api.json

HTTP API

Every phone serves an HTTP API on port 9800 of its local address. Workbench uses the same endpoints, so anything it does, your own tools can do too.

Base address: http://<iphone-ip>:9800

General

MethodPathWhat it does
GET/api/statusApp status, version and device info
GET/api/screenshot · /api/screenshotBase64Screenshot as JPEG (also as Base64)
GET/mirror/imageLive MJPEG screen stream
POST/api/runScriptRun a JavaScript snippet and return its result
GET/api/run · /api/stopRun or stop the loaded package
GET/api/appsList installed apps
GET/api/getClipboard · /api/setClipboardRead or write the clipboard
GET · POST/api/getAllConfig · /api/setConfigRead or change settings

Agent control

MethodPathWhat it does
GET/api/control/click · /doubleClickTap or double tap at x, y
GET/api/control/swipeSwipe between two points
GET/api/control/startApp · /stopApp · /activateAppStart, stop or activate an app by bundle ID
GET/api/control/home · /recent · /pressButtonHome screen, app switcher, hardware buttons
POST/api/control/w3cActionsStandard W3C Actions, including multi-touch
GET/api/sourceUI tree as XML

HID control

MethodPathWhat it does
GET/api/hid/click · /doubleClickHardware tap or double tap
GET/api/hid/move · /mouseDown · /mouseUpMove the pointer, press and release
GET/api/hid/swipeHardware swipe
POST · GET/api/hid/sendKey · /inputKey combinations and text
GET/api/hid/openApp · /closeApp · /openURLOpen or close an app by name, open a URL
GET/api/hid/deviceInfo · /restartDeviceAccessory info and restart

Keyboard

MethodPathWhat it does
GET/api/ime/input · /paste · /clearText · /getText · /pressEnter · /pressDelType, paste, clear, read text, Enter and Delete
GET/api/ime/isOkIs the ketec keyboard on screen

Files, media & logs

MethodPathWhat it does
GET · POST/api/file/list · /upload · /download · /deleteList, upload, download and delete files
GET · POST/api/media/saveImageToAlbum · /deleteAllPhotosSave to or clean up the photo library
GET/logger/current/lines · /logger/files · /logger/downloadLive log lines, log files and downloads

Agent endpoints need Agent mode and HID endpoints need HID mode. Endpoints act immediately, so be careful when probing a real device.

Full HTTP API reference · OpenAPI 3.1 (openapi.yaml) · openapi.json

Guide: Agent keep-alive · LAN mode — let one Linux host on your network keep ketec running on every phone, even after ketec is killed or the phone restarts.

Remote debugging & cloud control

Reach phones that are not on your desk.

Link code

Workbench generates an 8-digit code. Enter it on the phone under Settings › Remote Debugging and the phone appears in Workbench through the ketec relay. Either side can end the session.

Your own server

Point the phone at your own frp server with TCP or STCP mapping, import settings from the clipboard and map automatically on launch. Idle sessions can disconnect after 5, 10, 30 or 60 minutes.

Cloud control

Set a cloud control address and the phone keeps a WebSocket connection to your server, which can run scripts, take screenshots and send input. Scripts report data with cloud.report and listen with cloud.onEvent.

Full API reference with every parameter and return value is coming soon.