I was trying to improve my "Resize window below cursor" only resizes from bottom-right. - #26 by esv script to resize windows with a single keybind and a mouse, and instead of hardcoding coordinates where a mouse should move to to grab a window's side, I've tried using JS to get current corodinates and then maintain current X position for vertical movements (and Y positions for horizonal ones) so that the mouse jumps in a more pleasant fashion
I've copied the action to JS, but it still has a different effect: instead of resizing it clicks before the JS action is complete. Maybe it has to do with the async part???
The docs don't mention how to run a sequence of actions, so I've tried
// fails: let result = await callBTT('trigger_action',[{json:JSON.stringify(actionDefinition),wait_for_reply:false},{json:JSON.stringify(clickActionDef),wait_for_reply:false}]);
and also just
let result1 = await callBTT('trigger_action',{json:JSON.stringify(actionDefinition),wait_for_reply:false});
let result = await callBTT('trigger_action',{json:JSON.stringify(clickActionDef),wait_for_reply:false});
This seems to work better, but still not fully reliable, maybe because the order of execution is not guaranteed? Or I should wait for reply in the first call? What 's the correct wait to run multiple actions in a sequence preserving their order? (also tried to put two objects in an array in the actionDefinition
, but that didn't work)
This is a substitution script
(async ()=> { // save X coord of the previously saved mouse position to ๐x
var x = 1
var y = 1
const winRel = 1 // top-left
const mouse_pos = await callBTT('get_string_variable',{variable_name:'saved_mouse_position'})
const mouse_pos_arr = mouse_pos.replace("{","").replace("}","").split(", ")
if (mouse_pos_arr.length != 2) {
console.log(`tried to parse get_string_variable, but intsead of 2 numbers got โ${mouse_pos_arr}โ`)
returnToBTT()}
x = mouse_pos_arr[0]
let actionDefinition = {
"BTTTriggerType" : -1,
"BTTTriggerClass" : "BTTTriggerTypeMagicMouse",
"BTTPredefinedActionType" : 153,
"BTTPredefinedActionName" : "Move Mouse To Position",
"BTTGenericActionConfig" : "{400, 1}",
"BTTGenericActionConfig" : `{${x}, ${y}`,
"BTTMoveMouseToPosition" : `{${x}, ${y}`,
"BTTMoveMouseRelative" : `${winRel}`,
"BTTAdditionalConfiguration" : "1048584",
"BTTUUID" : "06ED07D3-F1D5-4DE9-AE41-8F34581B4162",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTRequiredModifierKeys" : 1048576,
"BTTOrder" : 2
};
let result = await callBTT('trigger_action',{json:JSON.stringify(actionDefinition),wait_for_reply:false});
returnToBTT(result);
})()
This is a currently working trigger without JS, JS substitutes the second action
[
{
"BTTLastUpdatedAt" : 1692169171.7556329,
"BTTTriggerConditionsReadOnly" : "percent_y_hovered_win_btm_left > 66 AND percent_x_hovered_win_btm_left > 33 AND percent_x_hovered_win_btm_left <= 66",
"BTTTriggerConditions" : "YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGvECELDBMaIiwtLzY6P0BDR0tQUVRbYGRpbnJ1dnl6fIGEhohVJG51bGzTDQ4PEBESXxAXTlNDb21wb3VuZFByZWRpY2F0ZVR5cGVfEA9OU1N1YnByZWRpY2F0ZXNWJGNsYXNzEAGAAoAg0hQPFRlaTlMub2JqZWN0c6MWFxiAA4AUgByAH9QPGxwdHh8gIV8QEU5TUmlnaHRFeHByZXNzaW9uXxAQTlNMZWZ0RXhwcmVzc2lvbl8QE05TUHJlZGljYXRlT3BlcmF0b3KAE4AOgASAEdUjJCUmDycoKSorWU5TT3BlcmFuZF5OU1NlbGVjdG9yTmFtZV8QEE5TRXhwcmVzc2lvblR5cGVbTlNBcmd1bWVudHOABoAFEAOACIANXHZhbHVlRm9yS2V5OtIlDxAugAfSMDEyM1okY2xhc3NuYW1lWCRjbGFzc2VzXxAQTlNTZWxmRXhwcmVzc2lvbqMyNDVcTlNFeHByZXNzaW9uWE5TT2JqZWN00hQPNzmhOIAJgAzTDyU7PD0+WU5TS2V5UGF0aIALEAqACl8QHnBlcmNlbnRfeV9ob3ZlcmVkX3dpbl9idG1fbGVmdNIwMUFCXxAcTlNLZXlQYXRoU3BlY2lmaWVyRXhwcmVzc2lvbqNBNDXSMDFERV5OU011dGFibGVBcnJheaNERjVXTlNBcnJhedIwMUhJXxATTlNLZXlQYXR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EAAAAAAAAAiwAAAAAAAAAAAAAAAAAABHI=",
"BTTTriggerType" : 643,
"BTTTriggerTypeDescription" : "Named Trigger: Resize@CursorPosition",
"BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
"BTTPredefinedActionType" : 154,
"BTTPredefinedActionName" : "Save Current Mouse Position",
"BTTTriggerName" : "Resize@CursorPosition",
"BTTUUID" : "6277C1E9-172C-452C-904E-7F86DA4D6C13",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTOrder" : 2,
"BTTAdditionalActions" : [
{
"BTTLastUpdatedAt" : 1692167897.564405,
"BTTTriggerType" : -1,
"BTTTriggerClass" : "BTTTriggerTypeMagicMouse",
"BTTPredefinedActionType" : 153,
"BTTPredefinedActionName" : "Move Mouse To Position",
"BTTGenericActionConfig" : "{400, 1}",
"BTTMoveMouseToPosition" : "{400, 1}",
"BTTMoveMouseRelative" : "1",
"BTTAdditionalConfiguration" : "1048584",
"BTTUUID" : "06ED07D3-F1D5-4DE9-AE41-8F34581B4162",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTRequiredModifierKeys" : 1048576,
"BTTOrder" : 2
},
{
"BTTLastUpdatedAt" : 1692167897.565105,
"BTTTriggerType" : -1,
"BTTTriggerClass" : "BTTTriggerTypeMagicMouse",
"BTTPredefinedActionType" : 119,
"BTTPredefinedActionName" : "Custom Mouse Buttons & Modifiers(โโฅโงโ)",
"BTTGenericActionConfig" : "1000",
"BTTGenericActionConfig2" : "1",
"BTTCustomClickConfig" : "1000",
"BTTCustomClickUpDownConfig" : "1",
"BTTUUID" : "F8F7B19D-78C7-44F8-A45C-C9EE9C6642C7",
"BTTEnabled" : 1,
"BTTEnabled2" : 1,
"BTTOrder" : 3
}
],
"BTTGestureNotes" : "โฌ๏ธ"
}
]