Skip to content

FindNode Examples

Real-world examples of FindNode queries and automation scripts.

Example 1: Bottom Navigation Bar

Finding and clicking navigation items:

javascript

// Get all navigation labels
device.sendAai({ query: "TP:appNavBar,labels", action: "getText" });
// Returns: { count: 5, retval: ['Alarms','World Clock','Timers','Stopwatch','Bedtime'] }

// Click the 4th item's icon (offset up from label)
device.sendAai({
  query: "TP:line,bottom,-1&&IX:3&&OY:-1",
  action: "getIds;click"
});

// Verify selection
device.sendAai({
  query: "TP:appNavBar&&BP:selected",
  action: "getText"
});
// Returns: { retval: 'Stopwatch' }

Example 2: Read Android Version

javascript

device.sendAai({
  action: `openAndroidSetting(DEVICE_INFO_SETTINGS);
    click(T:Software information);
    refreshQuery;
    getText('T:Android version&&OY:1')`
});
// Returns: { count: 4, list: [{retval: true},{retval: true},{retval: true},{retval: '16'}] }

Example 3: Send Message in Teams

javascript

function sendTeams(device, name, text) {
  var retval = device.sendAai({ actions: [\
    `scrollIntoView(T:${name})`,\
    "click",\
    "newQuery(TP:textInput)",\
    `setText('${text}')`,\
    "click(OX:2)",\
    "waitQuery(HT:Type a message)",\
    "sendKey(Back)"\
  ]});
  if (retval == null) {
    print("Error: " + lastError());
    return false;
  }
  return true;
}

sendTeams(device, "John Smith", "Hello from Total Control!");

Example 4: Samsung Calculator Automation

Complete script that opens the calculator, maps buttons, and computes formulas:

javascript

var { getDevice } = require('sigma/device');
var idList = {};

function sendAai(obj) {
  var retval = getDevice().sendAai(obj);
  if (retval == null) {
    throw "Error: " + lastError();
  }
  return retval;
}

function init() {
  sendAai({ action: "openApp(com.sec.android.app.popupcalculator)" });
  var list = sendAai({
    query: "T:/^[0-9+=-]$/",
    action: "getNodes(T)"
  }).retval;
  list.forEach((p) => idList[p.text + ""] = p.id);
}

function calc(formula) {
  var fList = formula.split("");
  var elemList = fList.map((p) => idList[p]);
  elemList.push(idList['=']);
  sendAai({
    elements: elemList,
    action: "forEach(nsClick);sleep(500)"
  });
  var result = sendAai({
    actions: "refresh(*R:.calc_edt_formula);getText"
  }).list[1].retval;
  return parseInt(result);
}

init();
print("Result: " + calc("123+456")); // Output: Result: 579

Example 5: Tesla App — Read Odometer

javascript

// Simple: find mileage text directly
device.sendAai({
  action: "openApp(Tesla);scrollIntoView(T:/^[0-9,]+ miles$/);getText"
});
// Returns: { retval: '9,999 miles' }

// Using VIN as anchor with offset
device.sendAai({
  action: "openApp(Tesla);scrollIntoView(T:VIN:&&OY:-1);getText"
});

// Get both mileage and VIN in one query
device.sendAai({
  action: "openApp(Tesla);scrollIntoView(T:VIN:);getText(OY:-1);getText(OX:1)"
});
// Returns: { list: [..., {retval: '9,999 miles'}, {retval: 'XXXXXXXXXXXXXXXXX'}] }

Tips

Query Development Workflow

  1. Open UI Explorer to inspect element properties
  2. Build your query in Terminal with sendAai()
  3. Once working, move to JavaScript (Rhino) for reusable scripts

Regex in Queries

Use /pattern/ syntax for regex matching: T:/^[0-9]+$/ matches numeric-only text. Use ci: prefix for case-insensitive: T:ci:hello

Sigma RT Total Control Documentation