Moving and resizing window

I'm unable to resize a window and center it. i'm using SCREENVISIBLE, which should exclude the menu bar and the dock but in my case it isn't. is there a work around for this?

Macro Image

You may find some help in this macro......

also for debugging, move each of the params(4) to a set of values (4) as result may not be what you were expecting.

SCREENVISIBLE() excludes the Dock area unless "Hiding" is turned on -- and it looks from your screenshot that it is. Try for yourself with a simple

image

...with different Dock settings. On my Air it gives "828" with the Dock always visible and "875" with it set to hide.

I'm using a MBP with an external display (1920x1080).
The height shows 1055
Should i save this to a variable and subtract 25? ==SCREENVISIBLE(Main,Height) -25==

1055 is probably the display height minus menu bar. Dock height will depend on Size in System Preferences/Settings and the number of icons currently in it -- if Hiding is turned on you won't get it right for every possible situation, so pick a number that stops you overlapping your "tallest" expected Dock even if that means leaving some space between window edge and Dock at other times.

Easy way to get the height of your Dock -- turn on "Mouse Display" from KM's "Window" menu, click the bottom-left "anchor", mouse over the Dock so it pops up, slowly mouse up until it hides read the unsigned ↓ number from the Mouse Display window. Then yes, it's SCREENVISIBLE(Main,Height) - thatNumber -- or if you still want 95% of that, (SCREENVISIBLE(Main,Height) - thatNumber) * 0.95

Got it, from my observation this is only affecting the height not the width. My dock is hidden on the left.

So that means SCREENVISIBLE() is somehow including the menubar's height.

No, if your Dock is on the left then you're correct -- 1055 from SCREENVISIBLE() + 25 for the menu bar = 1080.

But you'll see it isn't including your Dock in the width -- your window is 95% of your monitor's 1920 pixels, with 2.5% (48px) padding either side.

Remember, you've scaled the window to 95% of the "visible screen" -- which doesn't include the menu bar. But you've centred it on on the entire screen -- which does include the menu bar. That'll result in a vertical shift, with less padding between the menu bar and the window's top edge than between the bottom edge and the bottom of the display -- is that the discrepancy you mean?

If it is, change your action so it centres the window as you'd like -- pick the "Center at" option and use coordinates from SCREENVISIBLE():

image

Hey Guys,

I'm not following the thread closely, so forgive me if this isn't totally relevant.

Working with screens and windows can be very confusing – especially when you're new at it – and it can be useful to compare things like screen, screen visible, and window 1.

Do not forget that there are relevant text-tokens as well as functions.

A quick example:

image

Diagnosing Screen Issues v1.00.kmmacros (12 KB)

Macro Image

Keyboard Maestro Export

-Chris

Remember, you've scaled the window to 95% of the "visible screen" -- which doesn't include the menu bar. But you've centred it on on the entire screen -- which does include the menu bar. That'll result in a vertical shift, with less padding between the menu bar and the window's top edge than between the bottom edge and the bottom of the display -- is that the discrepancy you mean?

Yes, that make sense. When I center the window it's calculating the entire screen not the visible screen. I didn't think about that. Wonder if the menu bar size remains the same regardless of the screen size?

What i have here works for me

Macro Image

1 Like

One thing to watch for -- there have been various threads here lately about move/resize not completing so you end up with an oddly-sized window. For example, if your window is to the right of your screen and you try and resize to 95% of screen width it won't expand past the screen edge and then the "reduced" window will be positioned. There also seems to be an issue with combining move and resize in one action. (Note that these are OS problems, and not KM's fault!)

Some people have been using loops where they keep resizing until everything's correct. But I wonder if you might be able to avoid the problem by moving the window to top-left, resizing it, then positioning it:

image

In my experience -- it depends :wink: But don't wonder -- ask KM! Coz there's a function for that: MENUBARHEIGHT(). So for me (and also showing that the top of the "visible" screen is MENUBARHEIGHT() + 1):

image

...which for my 27" iMac on macOS 10.14 gives

image

1 Like