Get width and height of the display that the currently active window is on – with a multi-monitor setup

sorry that should be fixed in 4.023 alpha (uploading right now)

With this test script it now seems to always return the correct values for me:

(async () => {
const focusedScreenX = await callBTT("get_number_variable", {
        variable_name: "focused_screen_x"
    });
    const focusedScreenY = await callBTT("get_number_variable", {
        variable_name: "focused_screen_y"
    });
    const focusedScreenWidth = await callBTT("get_number_variable", { 
        variable_name: "focused_screen_width"
    });
    const focusedScreenHeight = await callBTT("get_number_variable", {
        variable_name: "focused_screen_height"
    });
  let result = {
        focusedScreenX: focusedScreenX,
        focusedScreenY: focusedScreenY,
        focusedScreenWidth: focusedScreenWidth,
        focusedScreenHeight: focusedScreenHeight
    };
	console.log("test");
returnToBTT(JSON.stringify(result));
})();
 
1 Like

Yup! Fixed – thanks!

To clarify: :slightly_smiling_face:

:white_check_mark: The issue that everything is undefined is fixed.

:white_check_mark: focused_screen_visible_frame_width etc. also works fine now, returns data for the screen that the active window is on.

:x: The issue that focused_screen_width etc. is always the x, y, width and height of the main screen is not fixed yet – but probably not needed, since we can use _screen_visible_frame, right?

are you sure? all of them work fine here when I try them in the test script above (the code for visible frame and standard is exactly the same apart from the property it accesses)

//edit did you maybe at some point set these variables via one of the set functions? In that case BTT would return the user-set value instead of the computed value. You can reset variables in the BTT settings under "Scripting BTT"

You're right, I've reset the custom variables like you suggested, now
:white_check_mark: focused_screen_width etc. works as expected

nice! I'll soon add some variables fro windows as well.

1 Like

Came here looking for focused window variables.

I have one shortcut, ⌘ ← that makes the current window 50% left.

I want to conditionally check if the width of the current window is LTE 50% of the current monitor, and if it is, decrease that window by 10%.

I tried doing it with BTTLastTriggeredACtion variable, but it got confusing and messy quickly. I rather do it based on the window position.

The focused_window_width and height variables will be available with the next BTT alpha!

1 Like