- Write Tasker task as Javascript module
- Map profile name to module
- Auto refresh script during development mode
with npm
npm install tasker-js-runner --save
with yarn
yarn add tasker-js-runner
import TaskerJs from 'tasker-js-runner';
// Tasker Javascript modules
import notification from './modules/notification';
// Construct Tasker JS and pass in mapping information as an Object
new TaskerJs({
// Profile name: module
'Notification:All': notification,
});
A module should contain an enter
and an exit
function.
The 2 functions will receive all the local variables from the profile's task
via locals
and a reference Tasker's global object via tasker
.
export default {
enter(locals, tasker) {
// Example: Accessing local variables %anapp and %antitle from AutoNotification
const content = locals.anapp + ' ' + locals.antitle;
// Tasker's function can be accessed via the `tasker` object.
tasker.setClip(content);
// If you wish, you can also omit `tasker` by calling Tasker's function directly.
// Behind the scene, `tasker` is mapped to the `window` object where the
// Tasker's function live.
flash('content');
},
exit(locals, tasker) {}
};
All module functions are wrapped inside a Promise, which will gracefully exit at the end of execution.
To ensure proper task exiting while running asynchronous code, always return a promise.
export default {
enter(locals, tasker) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (tasker.global('BLUE') === 'on') {
resolve();
} else {
reject();
}
}, 1000);
});
},
...
}
Otherwise, you can also permaturely terminte the script. This will immediately stop the script from executing.
export default {
enter(locals, tasker) {
setTimeout(() => {
tasker.exit()
}, 1000);
},
...
}
https://github.com/amoshydra/tasker-js-runner-project
- Import the 3 tasks from the
tasker-imports
folder into TaskerTJS_Development_Toggle.tsk.xml
TJS_RunScript.tsk.xml
TJS_UpdateScript.tsk.xml
- Run [TJS_Development_Toggle] inside Tasker to set up the required global variables
When [TJS_Development_Toggle] is run for the first time, it will set up all the necessary Global variables for Tasker-JS to run.
%TJS_ENV
- Control the environment Tasker-JS-Runner to rundevelopment
/production
.%TJS_DEV_REMOTE
- The remote address where the your project script (a seperate project that make use of this library) will be downloaded. You will need to change the value of this variable in this task to match the IP of your project.%TJS_LOCAL_PATH
- The location where the project script will be saved (default toDocuments/tasker-js-runner.js
)
- Create a Tasker named profile (i.e.
Notification:All
) and selectTJS:RunScript
as its task. - Tasker-JS-Runner will detect the profile name and look execute the Javascipt module that's mapped into
Notification:All
in the Profile Map (see example from above