Using JavaScript (not JXA)
Using Real JavaScript in BTT
NOTE: If you are using the floating webview action in BTT have a look here instead: Floating Webview JavaScript
This feature is new in BetterTouchTool version 3.333. I think it is the most powerful and easiest way to script BetterTouchTool.
It's basically just modern JavaScript (so you can use async await and the like) however it has a few important additions:
- It can call any AppleScript - and get the result
- It can call any Shell Script - and get the result.
- It can trigger all functions available in BetterTouchTool's scripting interface.
By combining these three you can automate almost any task on your Mac.

1.) Running Standard AppleScripts: runAppleScript(yourScript)
To run an AppleScript from within the JavaScript code, use the runAppleScript(scriptCode) function. The function takes a string that defines the AppleScript, and returns a promise which resolves to the result value.
I'm always using it with async await, but you can also use classic Promise syntax.
Example: Run AppleScript from within JavaScript
// You can either wrap your script in a self executing async function or a standard named async function.
// If you use a named function, you can use return instead of returnToBTT
async function someFunctionName() {
// put the AppleScript into a string (back ticks are great for multi-line strings)
let appleScript = `
set theDialogText to "The curent date and time is " & (current date) & "."
set result to display dialog theDialogText
return result
`;
// this will execute the AppleScript and store the result in the result variable.
let result = await runAppleScript(appleScript);
// do whatever you want with the result
// at the end you always need to call returnToBTT to exit the script / return the value to BTT.
return result;
}