Aller au contenu
CloudClick iOS

Référence de l'API de script

Toutes les interfaces du runtime de script : recherche d'éléments et touchers, sélecteurs, gestes et boutons, apps et écrans, globales, journaux et HTTP, photos, recherche de couleurs et d'images, reconnaissance de texte. Chacune documente ses paramètres, sa valeur de retour et ses erreurs, et chaque exemple s'exécute tel quel.

93 interfaces

Les descriptions des entrées ci-dessous sont en anglais.

Script minimal exécutable

A script must return true to count as a success; returning false or nothing is recorded as a failure. The runtime library is prepended to every script, so client, clickElement, logi, sleep and the rest are available directly.

javascript
function main() {
  // Open Settings and go into General
  client.session('com.apple.Preferences');
  sleep(2);

  if (!clickElement('label', 'General', 5)) {
    loge('General not found');
    return false;
  }

  logi('opened General');
  return true;
}

main();

Conventions générales

Arguments go in order
Every function takes its arguments in order — no {} options objects. The common ones come first and trailing ones can be left out; write null to keep the default for one in the middle, as in findImage('a.png', 0, null, 0.85). Passing an old-style {} throws INVALID_ARGUMENT, and the message contains the corrected line.
Locators say how to look
The first two arguments of the element functions are how to look and what to look for: clickElement('label', 'Log in'). There are exactly 7 strategies, named like the selectors: label (exact text), labelContains (text contains), accessibilityId (the element's name — the most stable), xpath, predicate, classChain and className.
Time is always in seconds
Every duration is in seconds and may be fractional. Lookup and read functions look once by default; tap functions wait up to 10 seconds. Values above 600 are rejected as milliseconds passed by mistake. The only exceptions are setTimeout and setInterval, which keep JavaScript's millisecond convention.
Coordinates and areas
Coordinates are points, not pixels: the x and y you get back can go straight into client.click, and the same script works on 2x and 3x screens. When x and y both fall between 0 and 1 they are screen ratios. Areas are written [x, y, w, h]: all four between 0 and 1 means screen ratios (portable across resolutions), otherwise points.
Several checks on one frame
Colour, image and text lookups take their own screenshot every time and release it afterwards. To check several things on the same frame, call keepScreen() first and releaseScreen() when done — or use withScreen(function () { … }), which releases the frame for you.
Stopping is cooperative
Pressing Stop in the console only sets a flag; it never interrupts the script by force. Long loops must check shouldStop() and exit when it returns true; sleep and the waits inside lookup functions return immediately after a stop.
Branch on error codes
Every error carries a stable code field. Branch on the code rather than the message text, which is written for people and changes between versions. Lookup functions return null or false on a miss instead of throwing; exceptions are reserved for real errors such as wrong arguments or device and WDA failures.

Modules

Elements7The group scripts use most. Arguments go in order: how to look, what to look for, and how many seconds to wait. A miss returns null or false instead of throwing; only a wrong argument throws INVALID_ARGUMENT.Selectors7A selector only builds an element object and does not look anything up yet; the lookup happens when you call exists / click / getText / getRect. Compared with findElement it can pick the n-th match and include hidden elements, but it does not wait.Gestures & keys19Taps, swipes, drags and pinches, plus hardware buttons and the keyboard. Coordinates can be points or 0–1 screen ratios; directional swipes re-randomise the start point, distance, angle and duration every time and follow a hand-like path.Apps & sessions6Open, switch to and terminate apps, and query their state. Opening and switching both go through client.session, which also sets up the automation session.Screen & system7Read the current screen's element tree, size and screenshot, open links, write the clipboard, and handle system alerts.Globals7Objects and functions injected before a script runs: the device client, script parameters, task and device IDs, the stop signal, and the shared error codes.Utilities14Logging, waiting, time, random numbers, Base64 and HTTP requests. All three log levels are uploaded to the task log and show up in the console in real time.Photos & files8Count and clear the photos and videos in the library, save images or videos into it, and download files into the app. The first call asks for photo library access.Colour & image matching13Find colours and images on screen — for things drawn into images or canvases that the element tree cannot see. Everything runs on the device without the network. Arguments go in order: what to find, how many seconds to wait, the area, and then rarely changed thresholds. Coordinates come back in points, ready for client.click.Text recognition5Recognise on-screen text with Apple's Vision framework, entirely on the device — no network and no screenshot upload. Prefer element lookups (clickElement) where they work: the element tree is structured, fast and exact. OCR is for text drawn into images or canvases that the element tree does not contain.