JavaScript (Rhino) Scripting
Total Control uses Mozilla Rhino as its JavaScript engine, providing full JS language support for complex automation.
Getting Device Objects
javascript
var { getDevice, getDevices, searchName, searchGroup } = require('sigma/device');
// Single device
var device = getDevice();
// All connected devices
var devices = getDevices();
// Find by name
var pixel = searchName("Pixel 4");
// Find by group
var testGroup = searchGroup("test-devices");Basic Operations
Open and Control Apps
javascript
var device = getDevice();
// Open app
device.sendAai({ action: "openApp(com.example.myapp)" });
// Click element
device.sendAai({ query: "T:Login", action: "click" });
// Enter text
device.sendAai({ query: "HT:Username", action: "setText(admin)" });
// Press key
device.sendAai({ action: "sendKey(Enter)" });Screenshots
javascript
// Save to PC
device.screenshot("C:/screenshots/test.png");
// Save to device
device.screenshotToDevice("/sdcard/test.png");
// Save to memory for comparison
device.screenshotToMemory(0);File Operations
javascript
// Upload file to device
device.upload("C:/files/config.json", "/sdcard/config.json");
// Download from device
device.download("/sdcard/logs/test.log", "C:/logs/");
// Read file on device
var content = device.readFile("/sdcard/config.json");Multi-Device Scripting
javascript
var { getDevices } = require('sigma/device');
var devices = getDevices();
// Run same action on all devices
devices.forEach(function(device) {
device.sendAai({ action: "openApp(com.example.app)" });
});
// Or use DeviceArray methods
var allDevices = getDevices();
allDevices.sendAai({ query: "T:Accept", action: "click" });System Functions
| Function | Description |
|---|---|
print(text) | Output to console |
delay(ms) | Pause execution |
lastError() | Get last error message |
lastOutput() | Get last output text |
exit() | Stop script |
execCommand(cmd) | Execute system command |
tcLoad(path) | Load JS or class file |
HTTP Requests
javascript
// TCHttpRequest for API calls
var req = new TCHttpRequest();
req.open("GET", "https://api.example.com/data");
req.send();
var response = req.responseText;Timers and Threading
javascript
// Timer (interval execution)
var timer = new TCTimer(function() {
print("Tick");
}, 5000);
// Thread
var thread = new TCThread(function() {
// Long-running task
delay(10000);
print("Thread done");
});
thread.start();Task Management
javascript
// Create task for parallel execution
var taskId = taskCreate("myScript.js", device);
// Check task status
var info = taskInfo(taskId);
// List running tasks
var tasks = taskList();
// Stop task
taskStop(taskId);Error Handling
javascript
var retval = device.sendAai({ query: "T:Submit", action: "click" });
if (retval == null) {
print("Error: " + lastError());
// Handle error
} else {
print("Success: " + JSON.stringify(retval));
}Script Recording
Total Control can record user interactions as scripts:
- Start recording in the Script window
- Interact with the device
- Stop recording
- Script is saved as
.jsor.tstfile - Replay the recorded script on one or more devices