Skip to main content

Global Module

Overview

The global module can be used by calling methods directly, without a prefix object name.

CLI

getCliArgs Get CLI command-line arguments

  • Get CLI command-line arguments
  • When using with AI, prefer CLI args first; fall back elsewhere if unavailable
  • Enables AI auto-parameter passing and post-pack testing from other sources
  • Requires EC standalone 6.9.0+
  • @return {null|JSON} JSON object; null means not launched from CLI
function main() {
let a = getCliArgs();
if (a == null) {
// Get from elsewhere
}
logd(JSON.stringify(a))
}

main();

Automation Engine

Get automation engine mode

  • Get automation engine mode
  • @return {string} single = single-app mode | dual = dual-app mode
function main() {
logd(getAutomationEngineMode())
}

main();

Set automation engine mode

  • Set automation engine mode
  • @param mode {string} single = single-app mode | dual = dual-app mode
  • @return {boolean} true
function main() {
logd(setAutomationEngineMode("single"))
}

main();

App Version

version Get application version

  • Get application version
  • @return string, e.g. 2.9.0
function main() {
logd(version())
}

main();

Script Start & Stop

exit Exit script

  exit();

isScriptExit Whether script has exited

  • Check whether the current EC thread has exited (main or child thread)
  • @return true if exited
function main() {
try {
while (true) {
sleep(1000)
logd("222")
if (isScriptExit()) {
break
}
}
logd("222")
} catch (e) {
logd(e)
if (isScriptExit()) {
return
}
}
}

main();

sleep Pause execution

  • Sleep
  • @param miSecond Milliseconds
function main() {
sleep(1000);
}

main();

execScript Load JS

  • Execute JS file or content
  • @param a_execType 1 = file, 2 = JS content
  • @param _acontent Path[see file module]e.g. /var/a.jsor JS content
  • @return Boolean; true = success, false = failure
function main() {
let d = "logd(1)"
let dx = execScript(2, d);
while (true) {
sleep(2000);
loge("fsadffsad")
}
}

main();

restartScript Restart script

  • Supports EC iOS standalone 2.2.0+
  • Restart script; useful for infinite loops or on exception.
  • Warning: powerful; control auto-restart carefully or force-kill to stop
  • @param path New IEC path, or null if not needed
  • @param stopCurrent Whether to stop the current script
  • @param delay Delay in seconds before execution
  • @return bool; true = success, false = failure
function main() {
logd("Running in script");
setStopCallback(function () {
restartScript(null, false, 3)
});

//setExceptionCallback(function (){
// restartScript(null,true,3)
//});
sleep(1000);
logd("Script ended")
}

main();

JS Import

require Import JS

  • Import JS module
  • @param path Path, e.g. local JS file or EC project path slib/a.js
  • @return module object
function main() {
// Note: do not put JS files in js/ or subdirectories
// Note: EC iOS standalone 1.3.+
let lib1 = require("res/lib.js")
new lib1(1, 2, 3).say()
let lib2 = require("res/lib2")
logd(lib2.add(1, 2))
}

main();
//Video:https://www.bilibili.com/video/BV1ES4y1f7qV?vd_source=2abc6be820f5a6382ebc0ceafc5dbe00&p=39&spm_id_from=333.788.videopod.episodes
// res/lib2.js content
function add(a, b) {
return a + b;
}

var a1 = 1
module.exports = {add, a1};
// res/lib2.js content
module.exports = function (name, age, money) {
this.name = name;
this.age = age;
this.money = money;
this.say = function () {
console.log('My name: ' + this.name + ', age ' + this.age + ', salary: ' + this.money);
}
};

JSON Processing

JSON.stringify Format to JSON string

  • Format object to JSON string
  • @param object
  • @return string
function main() {
var m = {"sss": "a"};
var d = JSON.stringify(m);
logd(d);
}

main();

JSON.parse Convert to JSON object

  • Parse JSON string to object
  • @param string
  • @return object
function main() {
var m = {"sss": "a"};
var d = JSON.stringify(m);
d = JSON.parse(d);
logd(d);
}

main();

Script & Service Listeners

setStopCallback Script stop listener

  • Supports EC iOS standalone 2.2.0+
function main() {
setStopCallback(function () {
logd("Stop callback")
});
var result = sleep(1000);
if (result) {
logd("Success");
} else {
logd("Failed");
}
}

main();

setExceptionCallback Script exception stop listener

  • Supports EC iOS standalone 2.2.0+
function main() {
setExceptionCallback(function (msg) {
logd("Exception stop message: " + msg)
});
var result = sleep(1000);
if (result) {
logd("Success");
} else {
logd("Failed");
}
// Exception thrown here
result.length();
}

main();

Logging Methods

setLogLevel Set log level

  • Set log level; enable or disable logging as needed
  • @param level Log level: debug, info, warn, error, off (debug < info < warn < error < off)
  • e.g. off = disable all; debug = logd/logi/logw/loge; info = logi/logw/loge; warn logw/loge only
  • @param displaylogd Whether to show logd messages; not implemented
  • @return {bool} Boolean true = success, false = failure
function main() {
setLogLevel("info", false)
for (var i = 0; i < 1; i++) {
sleep(10);
//logd(time()+" debug");
logi(time() + " info");
//logw(time()+" warn");
// loge(time()+" error");
logd("--- " + time());
}
//logd(time()+" 222");
}

main();

logd Debug log

  • Debug log
  • @param msg Message string
function main() {
logd("msg");
// Variadic arguments
logd("Message {},{}", "test1", 2)
}

main();

loge Error log

  • Error log
  • @param msg Message string
function main() {
loge("msg");
// Variadic arguments
loge("Message {},{}", "test1", 2)
}

main();

logw Warning log

  • Warning log
  • @param msg Message string
function main() {
logw("msg");
// Variadic arguments
logw("Message {},{}", "test1", 2)
}

main();

logi Info log

  • Info log
  • @param msg Message string
function main() {
logi("msg");
// Variadic arguments
logi("Message {},{}", "test1", 2)
}

main();

setDisplayLineNumber Display line numbers

  • Set whether logs show line numbers
  • Requires EC standalone 5.0.0+
  • @param display true = show line numbers
function main() {
setDisplayLineNumber(true)
for (var i = 0; i < 1; i++) {
sleep(10);
//logd(time()+" debug");
logi(time() + " info");
//logw(time()+" warn");
// loge(time()+" error");
logd("--- " + time());
}
//logd(time()+" 222");
}

main();

setSaveLogEx Save log

  • Save log output to files; export via iTools/i4
  • EC iOS 3.13+ adds level parameter
  • @param save Whether to save
  • @param level Log level,values: debug,info,warn,error,off,ordered as debug<info<warn<error,
  • e.g. off = disable all; debug = logd/logi/logw/loge; info = logi/logw/loge; warn logw/loge only
  • @return directory where log files are saved
function main() {
let d = setSaveLogEx(true, "debug")
logd(d)
}

main();

Log Window

setLogWindowForcePlaybackPaused Set log floating window pause state

  • Set whether log PiP is forced to paused state (low CPU mode).
  • Requires EC standalone 7.3.0+
  • System default is true
  • @param forcePaused {boolean}
  • true: always report paused; refresh at interval only; low CPU during script (recommended, default).
  • false: sync to playing during script (legacy; higher CPU).
  • @return {boolean} true on success
function main() {
// Call directly
setLogWindowForcePlaybackPaused(true)
}

main()

isLogWindowForcePlaybackPaused Query log floating window pause state

  • Query whether log floating window is forced paused (low CPU mode).
  • Requires EC standalone 7.3.0+
  • @return {boolean} true paused state
function main() {
// Call directly
logd(isLogWindowForcePlaybackPaused())
}

main()

setLogWindowInfoVisible Show or hide log floating window info bar

  • Show or hide log floating window info bar.
  • Requires EC standalone 7.3.0+
  • @param visible {boolean} true = show, false = hide
  • @return {boolean} true on success
function main() {
// Call directly
// Show first
setLogWindowInfoVisible(true)
// Set info to display again
setLogWindowInfoText("Account: test001\nCoins: 999\nStatus: Running\n1\n2", "", 12)
}

main()

setLogWindowInfoText Set log floating window custom info

  • Set log floating window custom info (below status bar, independent of log output).
  • Requires EC standalone 7.3.0+
  • @param text {string} important info to display,supports \n newlines (max 5 lines)
  • @param color {string} Optional hex text color, e.g. #FF6600;empty uses default log window text color
  • @param fontSize {number} Optional font size; 0 or omit uses default (1pt smaller than log text)
  • @return {boolean} true on success
function main() {
// Call directly
// Show first
setLogWindowInfoVisible(true)
// Set info to display again
setLogWindowInfoText("Account: test001\nCoins: 999\nStatus: Running\n1\n2", "", 12)
}

main()

setLogRefreshInterval Set log floating window refresh interval

  • Set log floating window refresh interval (seconds).Logs sync to PiP window at this interval.
  • Requires EC standalone 7.3.0+
  • @param intervalSec refresh interval in seconds,valid range 0.2–60, default 1
  • @return {boolean} true on success, false = invalid parameters
function main() {
// Call directly
setLogRefreshInterval(2)
}

main()

setLogViewSizeEx Set log window properties

  • Set log window size (extended)
  • @param map e.g.
  • Parameters:
  • x: start X position (X currently unused)
  • y: start Y position (Y currently unused)
  • w: width
  • h: height
  • textSize:log font size
  • textColor: text color #336699
  • line: number of lines to show; default 10
  • backgroundColor: background color, e.g. #336699
  • direction: text direction; 1 = portrait, 0 = landscape
  • showTag: show debug tag; 1 = yes, 2 = no
  • fitWidth: fit text to window width; 1 = yes, 0 = no
 function setlog() {
var m = {
"x": 2,
"y": 2,
"w": 300,
"h": 400,
"textSize": 26,
"backgroundColor": "#336699",
"textColor": "#000000",
"direction": 0,
"line": 10,
"showTag": 0,
"fitWidth": 0
}
// Bring main app to foreground
takeMeToFront()
sleep(1000)
showLogWindow();

logd("showLogWindow() " + showLogWindow())
for (let i = 0; i < 11; i++) {
sleep(1000)
logd("demo " + new Date())
if (i == 2) {
logd("closeLogWindow() " + closeLogWindow())
setLogViewSizeEx(m);
}
if (i == 10) {
logd("showLogWindow() " + showLogWindow())
}
}
}

setlog();

showLogWindow Show log window

  • [Cannot use while main app is in background]
  • Show log window; requires PiP support and PiP enabled on iOS
  • @returns {boolean} true = success, false = failure
 function setlog() {
var m = {
"x": 2,
"y": 2,
"w": 300,
"h": 400,
"textSize": 26,
"backgroundColor": "#336699",
"textColor": "#000000"
}
// Bring main app to foreground
takeMeToFront()
sleep(1000)
showLogWindow();

logd("showLogWindow() " + showLogWindow())
for (let i = 0; i < 11; i++) {
sleep(1000)
logd("demo " + new Date())
if (i == 2) {
logd("closeLogWindow() " + closeLogWindow())
setLogViewSizeEx(m);
}
if (i == 10) {
logd("showLogWindow() " + showLogWindow())
}
}
}

setlog();

closeLogWindow Close log window

  • [Cannot use while main app is in background]
  • Close log window
  • @returns {boolean} true = success, false = failure
 function setlog() {
var m = {
"x": 2,
"y": 2,
"w": 300,
"h": 400,
"textSize": 26,
"backgroundColor": "#336699",
"textColor": "#000000"
}
takeMeToFront()

showLogWindow();

logd("showLogWindow() " + showLogWindow())
for (let i = 0; i < 11; i++) {
sleep(1000)
logd("demo " + new Date())
if (i == 2) {
logd("closeLogWindow() " + closeLogWindow())
setLogViewSizeEx(m);
}
if (i == 10) {
logd("showLogWindow() " + showLogWindow())
}
}
}

setlog();

Read IEC Package Resources

readIECFileAsString Read IEC internal file as string

  • Read resource from IEC file and return string
  • @param fileName File name; include folder path if in a subfolder
  • @return {string}; null means no content
function main() {
var testData = readIECFileAsString("res/a.txt");
logd(testData)
}

main();

readResString Read string resource

  • Read resource from res/ and return string
  • @param fileName File name; do not include the res prefix
  • @return string; null means no content
function main() {
var testData = readResString("a.txt");
}

main();

readResAutoImage Read Image resource

  • Read resource from res/ and return AutoImage
  • @param fileName File name; do not include the res prefix
  • @return string; null means no content
function main() {
var b = readResAutoImage("img/a.png");
}

main();

saveResToFile Save resource to file

  • Save res/ resource to the given path
  • @param fileName File name; do not include the res prefix
  • @param path destination path,e.g./var/aa.txt
  • @return boolean true if saved successfully
function main() {
var b = saveResToFile("img/a.png", "/var/a.png");
}

main();

findIECFile Find IEC file

  • Find IEC files
  • @param dir Folder name; null = res/ only; default res/; e.g. res/aaa/
  • @param names File name prefix; null = no filter; separate with |, e.g. aaa|bb|cc
  • @param ext File extension; null = no filter; separate with |, e.g..png|.jpg|.bmp
  • @param recursion Whether to recurse subdirs; true = yes
  • @return {array} JSON array of file names
function main() {
let res = findIECFile("res/", "dd2", ".png|.jpg", true)
logd("findIECFile {}", JSON.stringify(res));

}

main();

UI Parameter Reading

deleteConfig Delete config value

  • @param key Key configured in the UI
  • @return {bool} true = success, false = failure
function main() {
var testData = deleteConfig("test_key");
}

main();

readConfigInt Read int config

  • @description Read UI parameter; returns int
  • @param key Key configured in the UI
  • @return int; returns 0 if not found
function main() {
var testData = readConfigInt("test_key");
}

main();

readConfigString Read string config

  • Read UI parameter; returns string
  • @param key Key configured in the UI
  • @return string; returns empty string if not found
function main() {
var testData = readConfigString("test_key");
}

main();

readConfigBoolean Read boolean config

  • Read UI parameter; returns boolean
  • @param key Key configured in the UI
  • @return true or false
function main() {
var testData = readConfigBoolean("test_key");
}

main();

getConfigJSON Get all config

  • Get config as JSON
  • @return JSON data
function main() {
var testData = getConfigJSON();
}

main();

updateConfig Update config

  • Update config
  • @param key Key
  • @param value Value
  • @return {boolean} true on success, false on failure
function main() {
updateConfig("a", "sss");
}

main();

Automation Service

isServiceOk Automation service status

  • Whether automation service is OK
  • @return true or false
function main() {
var result = isServiceOk();
}

main();

startEnv Start automation

  • Start automation service environment; not implemented — follow log output
  • @return true or false
function main() {
var result = startEnv();
}

main();

startActiveMySelf Start self-activation

  • Start self-activation; after activation, tap agent IP icon to launch
  • This function may take up to 30 seconds
  • See docs:https://ieasyclick.com/iostjdocs/advance/activemyself
  • Requires EC standalone 6.0.0+
  • For external VPN, bring main app to foreground to allow LocalDevVpn launch
  • @param openExtVpn string; 1 = external LocalDevVpn, 0 = built-in VPN
  • @return {string} "ok" = success; otherwise error message
function main() {
var result = startActiveMySelf("0");
logd("result " + result)
logd("mountDevImageOk " + mountDevImageOk())
}

main();

mountDevImageOk Mount developer image result

  • Whether developer image mount succeeded
  • Requires EC standalone 6.0.0+
  • @return {bool} true = success, false = failure
function main() {
var result = startActiveMySelf("0");
logd("result " + result)
logd("mountDevImageOk " + mountDevImageOk())
}

main();

Alert Sending

sendDingDingMsg Send DingTalk message

  • Send DingTalk message
  • Requires EC standalone 2.0.0+
  • @param url Group/dept bot Webhook URL
  • @param secret Bot Webhook secret; optional if using keyword filter
  • @param msg Message to send
  • @param atMobile Mobile numbers to @; comma-separated
  • @param atAll Whether to @all; true or false
  • @return {string} DingTalk JSON result, e.g. {"errcode":0,"errmsg":"ok"}; errcode=0 = success
function main() {
// Demo URL and secret. See this page for details: https://www.dingtalk.com/qidian/help-detail-20781541.html
// https://blog.csdn.net/weixin_44646065/article/details/110637713
let url = "https://oapi.dingtalk.com/robot/send?access_token=59735fa75d835dbfaa502bb42886fca982960d20sac5e1df6bba4dd1aba02999c"
let sec = "SEC2305788ab08e9534a33b86ae376697d3c9ee3095f331345d5ccd6e2e065ca8069"
var res = sendDingDingMsg(url, sec, "My message", "", true);
logd("sendDingDingMsg:" + res);
}

main();

Time

time Current timestamp in milliseconds

  • Current timestamp in milliseconds
  • @return {long} time in milliseconds
function main() {
logd(time());
}

main();

timeFormat Format time

  • Format current time, e.g.:yyyy-MM-dd HH:mm:ss
  • @return {string} formatted current time
function main() {
logd(timeFormat("yyyy-MM-dd HH:mm:ss"));
}

main();

console.time Start timer

  • Start timer; pair with timeEnd to measure duration
  • @param label Label
  • @return {long} current time
function main() {
console.time("1");
sleep(1000)
logd(console.timeEnd("1"))
}

main();

console.timeEnd End timer

  • End timer; pair with time start to measure duration
  • @param label Label
  • @return {long} elapsed since timer start
function main() {
console.time("1");
sleep(1000)
logd(console.timeEnd("1"))
}

main();

Start Debug Server

startDebugServer Start Debug Server

  • Packaged builds can also start debug server for IDE connection
  • @return Boolean; true on success, false on failure
function main() {
logd(startDebugServer())
}

main();

other

isReleaseIec Whether release version

  • Whether IEC script is release version
  • Requires EC standalone 5.9.0+
  • @return boolean; true = release, else debug
function main() {
var result = isReleaseIec();
logd(result);
}

main();

getDeviceExpTime Get authorization time

  • Get authorization expiry time
  • Supports EC iOS standalone2.0+
  • @return {string} null or "" = not obtained; otherwise expiry time string
function main() {
var result = getDeviceExpTime();
logd(result);
}

main();

setPipCtrlScript Set floating window script start/stop control

  • Set whether floating window controls script start/stop; prevents stop when video apps take focus
  • @param ctrl true = can control, false = cannot control
  • @returns {boolean} true = success, false = failure
function main() {
setPipCtrlScript(true);
}

main();

random Random function

  • Random value in range
  • @param min Minimum
  • @param max Maximum
  • @return int between min and max inclusive
function main() {
var result = random(100, 1000);
sleep(result);
}

main();

takeMeToFront Bring this app to foreground

  • Bring this app to foreground
  • @return boolean true = success, false = failure
function main() {
var result = takeMeToFront();
logd(result);
}

main();

getMyBundleId Get IPA bundle ID

  • Get IPA bundle ID
  • Requires EC iOS 4.8.0+
  • @return {string} string
function main() {
var result = getMyBundleId();
logd(result);
}

main();

getMyAppName Get IPA app name

  • Get IPA app name
  • Requires EC iOS 4.8.0+
  • @return {string} string
function main() {
var result = getMyAppName();
logd(result);
}

main();