Scripting guide

HTTP API

  1. Endpoints return JSON, for example {"version":"1.0.1","code":0}. A nonzero code indicates an error. Call the endpoint to inspect any returned data.
  2. The HTTP service uses port 8080. Make sure no other local service is using that port.
  3. For setcurrentrecordparam, first write the parameters to /var/mobile/ctwparams.txt.
  4. For endpoints that require a record ID, use getbakidfromname to look up the ID from its name.

Use the client device's IP address. The examples below use http://127.0.0.1:8080.

EndpointDescription
/versionGet the client version.
/newrecordClear all records and create a new one.
/nextrecordGet the next record.
/deleteallrecordsClear all records.
/activerecord?ID=XXXActivate the record with ID XXX.
/activefirstrecordActivate the first record.
/activelastrecordActivate the last record.
/deleterecord?ID=XXXDelete the record with ID XXX.
/importdirectImport records directly.
/exportrecord?ID=XXXExport the record with ID XXX.
/exportallrecordsExport all records.
/renamecurrentrecord?name=XXXRename the current record. URL-encode names containing Chinese characters.
/getbakidfromname?name=XXXLook up the ID for the record named XXX.
/getcurrentrecordparamGet the current record's parameters.
/setcurrentrecordparamRead parameters from /var/mobile/ctwparams.txt and apply them to the current record. This command is unsupported after 1.5.2. See Customer identifier for sending custom parameters.
/enablerecordappEnable or disable an app for the current record. Pass bid as the bundle ID and enable as 1 or 0.
/getallrecordsnameGet a list of all record names.
/relocationwithbidSet a GPS position. The parameters x, y, z, r and bid supply coordinates, altitude, randomization range and bundle ID.
/loadcloudconfig?device_id=XXXDownload a configuration shared by QR code. Use the sharing device's ID.

OpenURL commands

ActionCommand and notes
Launch the appopenURL("CTW://?cmd=open");
One-Tap ResetopenURL("CTW://?cmd=newrecord");
Next recordopenURL("CTW://?cmd=nextrecord");
Clear all recordsopenURL("CTW://?cmd=deleteallrecords");
Activate a specific recordopenURL("CTW://?cmd=activerecord&ID=");
Activate the first recordopenURL("CTW://?cmd=activefirstrecord");
Activate the last recordopenURL("CTW://?cmd=activelastrecord");
Delete a specific recordopenURL("CTW://?cmd=deleterecord&ID=");
Import records directlyopenURL("CTW://?cmd=importdirect");
Place records in /var/mobile/Media/CTWImport/.
Export a specific recordopenURL("CTW://?cmd=exportrecord&ID=");
Output is written to /var/mobile/Media/CTWExport/.
Export all recordsopenURL("CTW://?cmd=exportallrecords");
Output is written to /var/mobile/Media/CTWExport/.
Rename the current recordopenURL("CTW://?cmd=renamecurrentrecord&name=");
URL-encode names containing Chinese characters.
Find an ID by record nameopenURL("CTW://?cmd=getbakidfromname&name=");
Get current record parametersopenURL("CTW://?cmd=getcurrentrecordparam");
The output is in /var/mobile/ctwparams.txt.
Set current record parametersopenURL("CTW://?cmd=setcurrentrecordparam");
Supply parameters in /var/mobile/ctwparams.txt. This command is unsupported after 1.5.2. See Customer identifier for sending custom parameters.
Enable or disable an appopenURL("CTW://?cmd=enablerecordapp");
Use bid for the bundle ID and enable=1 or enable=0.
List all record namesopenURL("CTW://?cmd=getallrecordsname");
The list is written to /var/mobile/ctwrecords.txt.
Set a GPS locationopenURL("CTW://?cmd=relocationwithbid");
Use x, y, z, r and bid for coordinates, altitude, randomization range and bundle ID.
Download a QR-shared configurationopenURL("CTW://?cmd=loadcloudconfig&device_id=");
Supply the sharing device's ID.

Return codes

Read the return code from /var/mobile/ctwresult.txt.

CodeMeaning
0The command completed successfully.
1The command failed.
2The command is still running.
4There is no next record. Applies only to nextrecord.

Parameter file

/var/mobile/ctwparams.txt holds the current record's parameters. Write one parameter per line using chr(10) for line breaks and a colon between each name and value. Run getcurrentrecordparam and open the file to see the format.

ParameterDescription
RecordIDRecord identifier, for example WeChat001.
RecordNameRecord name, generated automatically by default.
DeviceNameDevice name, for example xxxx iPhone.
SystemVersionSystem version, for example 10.3.1.
IDFAAdvertising identifier.
IDFVVendor identifier.
UDIDDevice UDID.
IMEIDevice IMEI.
SerialNumDevice serial number.
MACMAC address.
SSIDSSID value.
BSSIDBSSID value.

TouchSprite examples

URL encoding

function encodeURI(s)
  s = string.gsub(s, "([^%w%.%- ])", function(c)
    return string.format("%%%02X", string.byte(c))
  end)
  return string.gsub(s, " ", "+")
end

Activate a record

recordId = encodeURI("1458774551");
url = string.format("CTW://?cmd=activerecord&ID=%s", recordId);
openURL(url);

Rename the current record

recordName = encodeURI("1458774551");
url = string.format("CTW://?cmd=renamecurrentrecord&name=%s", recordName);
openURL(url);

Launch the app

openURL("CTW://?cmd=open");