Based on @mvaneijgen script I created one which resets the cycle after a two second timeout
I changed it to "Real Javascript", as this is recommended by BTT. Just make sure you select "Source Type: Real JavaScript" in the Action Configuration.
Use this for the left side window placement:
(async ()=> {
// action definitions
const actionPlaceLeftHalf = {
"BTTPredefinedActionType" : 19,
"BTTPredefinedActionName" : "Maximize Window Left",
};
const actionPlaceLeftTwoThirds = {
"BTTPredefinedActionType" : 174,
"BTTPredefinedActionName" : "Resize window to Left Two Thirds",
};
const actionPlaceLeftThird = {
"BTTPredefinedActionType" : 108,
"BTTPredefinedActionName" : "Resize window to Left Third",
};
// system variables
let result = 'error happened!';
const lastTriggeredTime = await callBTT('get_number_variable', {variable_name:'PlaceLeftCycleLastTriggerTime'})
// reset, if trigger was pressed 2 seconds ago
if (lastTriggeredTime + 2000 < Date.now()){
await callBTT('set_number_variable', {variable_name:'placeLeftCycle', to: 1});
}
const alloyCycle = await callBTT('get_number_variable', {variable_name:'placeLeftCycle'});
// cycling on repeated press
if (alloyCycle == 1) {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceLeftHalf)});
result = await callBTT('set_number_variable', {variable_name:'placeLeftCycle', to: 2});
} else if (alloyCycle == 2) {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceLeftTwoThirds)});
result = await callBTT('set_number_variable', {variable_name:'placeLeftCycle', to: 3});
} else if (alloyCycle == 3) {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceLeftThird)});
result = await callBTT('set_number_variable', {variable_name:'placeLeftCycle', to: 1});
} else {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceLeftHalf)});
result = await callBTT('set_number_variable', {variable_name:'placeLeftCycle', to: 1});
}
callBTT('set_number_variable', {variable_name:'PlaceLeftCycleLastTriggerTime', to: Date.now()})
returnToBTT(result);
})();
and this for the right side:
(async ()=> {
// action definitions
const actionPlaceRightHalf = {
"BTTPredefinedActionType" : 20,
"BTTPredefinedActionName" : "Maximize Window Right",
};
const actionPlaceRightThird = {
"BTTPredefinedActionType" : 110,
"BTTPredefinedActionName" : "Resize window to Right Third",
};
const actionPlaceRightTwoThirds = {
"BTTPredefinedActionType" : 175,
"BTTPredefinedActionName" : "Resize window to Right Two Thirds",
};
// system variables
let result = 'error happened!';
const lastTriggeredTime = await callBTT('get_number_variable', {variable_name:'PlaceRightCycleLastTriggerTime'})
// reset, if trigger was pressed 2 seconds ago
if (lastTriggeredTime + 2000 < Date.now()){
await callBTT('set_number_variable', {variable_name:'placeRightCycle', to: 1});
}
const alloyCycle = await callBTT('get_number_variable', {variable_name:'placeRightCycle'});
// cycling on repeated press
if (alloyCycle == 1) {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceRightHalf)});
result = await callBTT('set_number_variable', {variable_name:'placeRightCycle', to: 2});
} else if (alloyCycle == 2) {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceRightTwoThirds)});
result = await callBTT('set_number_variable', {variable_name:'placeRightCycle', to: 3});
} else if (alloyCycle == 3) {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceRightThird)});
result = await callBTT('set_number_variable', {variable_name:'placeRightCycle', to: 1});
} else {
result = await callBTT('trigger_action', {json: JSON.stringify(actionPlaceRightHalf)});
result = await callBTT('set_number_variable', {variable_name:'placeRightCycle', to: 1});
}
callBTT('set_number_variable', {variable_name:'PlaceRightCycleLastTriggerTime', to: Date.now()})
returnToBTT(result);
})();