System utilities module for the Total Control scripting environment.
This module (path: "sigma/common/system") exposes lightweight host-side helpers
that interact with the desktop OS and the Total Control (TC) runtime. Use it to
execute local shell commands, read the system clipboard, and query TC’s language
and API version. It is framework-agnostic: functions are exported directly and are
not attached to Device objects.
Import path: require("sigma/common/system")
Features
- Run native commands on the host OS and capture stdout/stderr
- Return command output as a single string or as an array of lines
- Optionally filter out empty lines from command output
- Read the desktop clipboard as plain text
- Query the current TC scripting API version (e.g., "2.1.0.20911")
- Query the TC UI language (e.g., "zh", "en")
API
-
execCommand(cmd: string, opt?: { outputArray?: boolean, ignoreEmpty?: boolean }): string | string[] | null
Execute a shell command on the current computer. WhenoutputArrayistrue,
returns an array of lines; otherwise returns a single string. WhenignoreEmpty
istrue, removes empty lines from the result. Returnsnullon error and
sets a descriptive message vialastError(). -
TCgetClipboardText(): string | null
Return the current text contents of the desktop clipboard, ornullif the
clipboard does not contain text or is unavailable. -
TCgetAPIVersion(): string
Return the TC scripting API version. Useful for feature gating and compatibility checks. -
TCgetLanguage(): string
Return the TC installation language code, such as"zh"or"en".
Usage Examples
// Import (only this path is supported for this module)
var { execCommand, TCgetClipboardText, TCgetAPIVersion, TCgetLanguage } = require("sigma/common/system");
// 1) Run a command and get a single string
var cmd = java.lang.System.getProperty("os.name").toLowerCase().indexOf("win") >= 0
? "cmd /c netstat -a"
: "sh -c netstat -a";
var out = execCommand(cmd);
if (out == null) {
print("Command failed: " + lastError());
} else {
print(out);
}
// 2) Run a command and get an array of non-empty lines
var lines = execCommand(cmd, { outputArray: true, ignoreEmpty: true });
if (!lines) {
print("Command failed: " + lastError());
} else {
lines.forEach((line) => print(line));
}
// 3) Read clipboard text
var clip = TCgetClipboardText();
print("Clipboard: " + (clip == null ? "<empty>" : clip));
// 4) Check API version and language
var apiVer = TCgetAPIVersion();
var lang = TCgetLanguage();
print("TC API: " + apiVer + ", language: " + lang);
// Feature gating by version
if (TCgetAPIVersion().startsWith("2.1")) {
// Use features available in 2.1.x
}
Notes & Caveats
- Import path matters: This documentation applies only to
sigma/common/system. - Shell differences: On Windows, use
cmd /c <command>; on macOS/Linux, usesh -c <command>. - Blocking behavior:
execCommandwaits for the process to exit. Long-running commands
will block the script until completion. - Error reporting: On non-zero exit codes, the function returns
nulland includes the
captured stderr inlastError(). - Clipboard format:
TCgetClipboardTextreturns only plain text. Non-text clipboard
formats will result innull.
Functions
(inner) TCgetAPIVersion() → {string}
Retrieves the version number of the Total Control scripting API currently in use.
The obtained version number is the same as the value of "requireVersion" in the recorded script.
Example
// Get and print the current Total Control API version
var ret = TCgetAPIVersion();
print(ret);
// If it executes successfully, it will return:
2.1.0.20911
Returns:
| string |
If successful, the version number of the current script is returned. |
| string | null |
The text content of the clipboard, or |
| string |
If successful, return the language of the Total Control installation platform, zh for Chinese, en for English, etc. |
| string | cmd |
The command executed. (e.g., |
|||||||||||
| Object | opt |
<optional> |
Contains two fields, for example: {outputArray: true, ignoreEmpty: true}). Properties
|
Returns:
| string | null |
Returns the result of executing the command. |