JavaScript is a scripting feature in Tasker that allows users to execute JavaScript code within tasks and scenes. Through JavaScript, users can access Tasker variables, call Tasker actions as functions, manipulate scenes, process data, interact with web services, and create advanced automation logic.
Tasker's JavaScript support is available through the JavaScriptlet and JavaScript actions, as well as within WebView scene elements.
JavaScript provides an alternative programming environment within Tasker. Unlike traditional Tasker actions, JavaScript allows users to write custom logic using variables, conditions, loops, functions, and objects.
Tasker integrates JavaScript directly with its automation engine, enabling Tasker variables and actions to be accessed from JavaScript code.
The JavaScriptlet action allows JavaScript code to be written directly inside a Tasker task.
JavaScriptlets execute sequentially alongside other Tasker actions and can read and modify Tasker variables.
The JavaScript action executes JavaScript code stored in an external file.
This allows larger scripts to be maintained separately from tasks and edited using external tools.
JavaScript can also be embedded within WebView scene elements.
This allows users to create interactive user interfaces using HTML, CSS, and JavaScript.
Example:
<h1 onclick="setWifi(false)">
Turn Off Wi-Fi
</h1>
Tasker local variables are automatically available in JavaScript without the % prefix.
Example:
Tasker:
%name
JavaScript:
flash(name);
Changes made to local variables within JavaScript are reflected in subsequent Tasker actions.
Global variables must be accessed using helper functions.
Example:
var wifi = global("WIFI");
Setting a global variable:
setGlobal("MyVar", "Hello");
Tasker arrays are automatically converted to JavaScript arrays and vice versa.
Example:
Tasker:
%arr(1)
JavaScript equivalent:
arr[0]
Important differences:
JavaScript arrays begin at index 0.
Tasker arrays begin at index 1.
JavaScript uses square brackets.
Tasker uses parentheses.
Tasker exposes many actions as JavaScript functions.
Examples include:
setWifi(true);
setBT(true);
setAirplaneMode(false);
flash("Task Complete");
flashLong("Automation Finished");
mediaControl("play");
mediaControl("pause");
call("5551234567", true);
sendSMS("5551234567", "Hello");
writeFile("/sdcard/test.txt", "Hello World");
showScene("Dashboard");
hideScene("Dashboard");
Tasker's JavaScript functions cover a wide range of automation capabilities:
Audio control
Bluetooth management
Wi-Fi management
Mobile data control
File operations
Notifications
Telephony
Media playback
Scene manipulation
Image processing
Location services
Device settings
Task execution
Intent sending
Clipboard management
JavaScript is commonly used with Tasker Scenes.
Functions are available to:
Change element text
Change colors
Move elements
Show or hide elements
Update interfaces dynamically
Example:
elemText("Dashboard", "Status", "repl", "Connected");
JavaScript supports standard browser technologies, including:
JSON
XMLHttpRequest
External JavaScript libraries
This allows communication with APIs and web services directly from Tasker.
Only one JavaScript script executes at a time within Tasker.
Scripts execute alongside normal Tasker actions and can interact with running tasks and profiles.
When using asynchronous functions such as:
setTimeout(...)
the Auto Exit option should typically be disabled, and the script must manually call:
exit();
to allow Tasker to continue execution.
JavaScript is commonly used for:
Data processing
API communication
JSON parsing
Web service integration
Dynamic user interfaces
Complex calculations
Scene interaction
File management
Device control
Custom automation logic
Feature
JavaScript
Java Code
Language
JavaScript
Java (BeanShell)
Built-in Tasker Functions
Yes
Yes
Android API Access
Limited
Extensive
Web APIs
Yes
Limited
Scene Integration
Excellent
Limited
HTML/WebView Support
Yes
No
JSON Handling
Excellent
Good
Android Framework Access
Limited
Full
Only one JavaScript script may execute at a time.
Global arrays are not supported.
Some built-in functions require root access.
JavaScript actions cannot directly access all Android APIs.
Settings changed through JavaScript are not automatically restored when a profile exits.
JavaScript has been part of Tasker since its early releases and remains one of the platform's most powerful scripting options. It allows users to extend Tasker's capabilities beyond standard actions while remaining easier to learn than Android's Java APIs.
Java
Java Function
Java Code
Scenes
Variables
Tasks
WebView
Tasker AI Generator