JavaScript API
The JS API provides direct scripting access within Total Control using Mozilla Rhino JavaScript engine.
Download: JS API Manual (CHM)
Unique JS API Features
Features available only in the JS API (not REST):
| Feature | Description |
|---|---|
| Excel | Read/write Excel files |
| Keyboard | Create and manage keyboard shortcuts |
| TCThread | Multi-threading support |
| Trigger | Event-driven automation |
| Notification | Monitor device notifications |
| MTE | Managed Test Execution framework |
Excel Operations
javascript
// Read Excel
var excel = new Excel("C:/data/test.xlsx");
var value = excel.get(0, 0); // row 0, col 0
excel.setSheet(1); // switch sheet
var data = excel.readExcel(); // read all
// Write Excel
excel.set(0, 0, "Result");
excel.save();
excel.close();Keyboard Shortcuts
javascript
// Create shortcut
var kb = new Keyboard("Ctrl+F1", function() {
print("Shortcut triggered!");
device.sendAai({ query: "T:Start", action: "click" });
});
// List shortcuts
var shortcuts = Keyboard.searchObject();
// Remove shortcut
kb.unregister();Threading
javascript
// Create and run thread
var thread = new TCThread(function() {
for (var i = 0; i < 10; i++) {
device.sendAai({ action: "click(T:Refresh)" });
delay(1000);
}
});
thread.start();
// Wait for thread completion
TCWait([thread]);Event Triggers
javascript
// Create trigger for device events
var trigger = new Trigger("appChange", function(event) {
print("App changed to: " + event.app);
});
// Anti-sleep trigger
Trigger.antiSleep(true); // prevent device auto-sleep
// List triggers
Trigger.list();
// Disable trigger
trigger.disable();Notification Monitoring
javascript
var notif = new Notification();
notif.setDevice(device);
notif.setApp("com.whatsapp");
notif.setMatch("New message");
notif.setListener(function(msg) {
print("WhatsApp: " + msg);
// Auto-respond or log
});MTE (Managed Test Execution)
javascript
// Test context
var context = MTE.getContext();
var device = MTE.getDevice();
// Set test status
MTE.setStatus("PASS");
MTE.setMessage("Login test completed");
// Stop test
MTE.stop();Global Shared Object
Share data between scripts using _shared:
javascript
// Script A
_shared.testData = { users: 100, passed: 95 };
// Script B
var data = _shared.testData;
print("Pass rate: " + (data.passed / data.users * 100) + "%");System Utilities
javascript
// Format output
console.log("Status: %s, Count: %d", "OK", 42);
// Load external scripts
tcLoad("helpers/utils.js");
sigmaLoad("sigma/advanced");
// Prompt for user input
var name = prompt("Enter device name:");
var choice = winSelectButtons("Select mode", ["USB", "TCP", "Cancel"]);Preload Scripts
Configure scripts to load automatically when Total Control starts:
- Place scripts in the preload directory
- They execute before any manual script
- Good for setting up global functions and shortcuts