Can't get Javascript as text execution to work for scripting

I wrote a script to cycle window resizing through corners as a single hotkey. I initially wrote it in Javascript and used the text field in BTT to try to execute it, but it didn't work in either sync or async modes. However, if I ran it as an external file async, it does work. As per this issue to avoid memory leaks, I decided to run it as an Applescript as text instead (as opposed to executing a file), which works fine. I'm wondering if anyone can see an issue with the Javascript version as to why it wouldn't work, or maybe it's just a bug with the Javascript script runner in BTT.

Short version:
JS version works as file, not directly input to BTT. Applescript version works as file and direct input, using direct input to avoid memory leak.

Javascript version:

var BTT = Application("BetterTouchTool");

var currentCornerIndex = BTT.get_number_variable("currentCornerIndex") || 0;
var actionDefinition = {};

switch (currentCornerIndex) {
	case 0:
		actionDefinition = { "BTTPredefinedActionType" : 90 };
	case 1:
		actionDefinition = { "BTTPredefinedActionType" : 92 };
	case 2:
		actionDefinition = { "BTTPredefinedActionType" : 93 };
	case 3:
		actionDefinition = { "BTTPredefinedActionType" : 91 };


currentCornerIndex = (currentCornerIndex + 1) % 4;

BTT.set_number_variable("currentCornerIndex", {to: currentCornerIndex});

Applescript version:

tell application "BetterTouchTool"
	set currentCornerIndex to get_number_variable "currentCornerIndex"
	if currentCornerIndex is equal to missing value then
		set currentCornerIndex to 0
	end if
	if (currentCornerIndex = 0) then
		trigger_action "{\"BTTPredefinedActionType\":90}"
	else if (currentCornerIndex = 1) then
		trigger_action "{\"BTTPredefinedActionType\":92}"
	else if (currentCornerIndex = 2) then
		trigger_action "{\"BTTPredefinedActionType\":93}"
	else if (currentCornerIndex = 3) then
		trigger_action "{\"BTTPredefinedActionType\":91}"
	end if
	set currentCornerIndex to (currentCornerIndex + 1) mod 4
	set_number_variable "currentCornerIndex" to currentCornerIndex
end tell

Your Apple Script version seems to work perfectly fine here when using the async/background execution.

I'll check why the JS version doesn't work.


Sorry should have mentioned:

OS X High Sierra 10.13.6
BTT version: 2.669 (977)

The JS issue is a bug in the current BTT version. I have just fixed it, the fix will be included in the next alpha, later today!


Should now work in v2.670 alpha