SUBROUTINE: Vertical Alignment of Windows Using Percentages—SCREEN, SCREENVISIBLE, MENUBARHEIGHT


When positioning windows vertically (one above another) I've found that I need to use SCREENVISIBLE and an offset to the Y position.

I tried various combinations of SCREEN, SCREENVISIBLE, and offset values. This seems to the settings that work best for my Macs.

I selected 23 because the vertical dimension of my menubar is 24 pixels on my 16" MBPro and 22 pixels on my Mac mini (displayed on my 27" iMac with target display mode).

Am I missing something that would make this easier?


DOWNLOAD Macro File:
Position N Windows.kmmacros (7.6 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image

Hi @peternlewis. Is there a simpler method to align windows vertically?

The MENUBARHEIGHT function returns the height of the menu bar.

The SCREENVISIBLE function returns the coordinates of the visible area of the screen, which excludes the menu bar and the dock area.

Note that at least on my Mac, SCREENVISIBLE(Main,Top) + 1 == MENUBARHEIGHT().

I'm not really sure what you are trying to do, so I don't really know what a simpler method might be.

1 Like

@peternlewis, thank you very much for the reply!

My objective was to create a subroutine macro that positions and resizes windows specifying x, y, width, and height (all in percentages), e.g., 0 0 50 60, 0 60 50 40, and 50 0 50 100.

Ah, thank you! I missed that function in the wiki/documentation.

With that information, my subroutine now uses this action:

I suspect you intended: SCREENVISIBLE(Main,Top) - 1 == MENUBARHEIGHT()

On my Macs:

25 - 1 == 24 (16" MB Pro)

23 - 1 == 22 (Mac mini displayed on 27" iMac with target display mode)


For those that might be interested, here's the subroutine:

DOWNLOAD Macro File:
sub—Position-Resize Front Window.kmmacros (8.1 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image


And here's an example usage:

DOWNLOAD Macro File:
Position 3 Windows.kmmacros (4.1 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image

1 Like

I believe

  • SCREENVISIBLE(Main,Left,local_x/100)
  • SCREENVISIBLE(Main,Top,local_y/100)
  • SCREENVISIBLE(Main,Width)*local_w/100
  • SCREENVISIBLE(Main,Height)*local_h/100

Should do what you want.

1 Like

@peternlewis, again thanks for the reply!

Your recommendations work perfectly with a few minor exceptions that I thought might interest you and others:

  • With Mojave (macOS 10.14.6) if the Dock is right/visible, the right window partially overlaps the Dock.

  • With Monterey (macOS 12.3.1), the same behavior is seen but only under certain sequencing:

    • If the Dock preferences are left/visible and then changed to right/visible, there is no window/Dock overlap.

    • If the Dock preferences are left/autohide, changed to right/autohide, and then changed to right/visible, there is a window/Dock overlap.

  • With Mojave (macOS 10.14.6), if System Preferences > General > Automatically hide and show the menu bar, then the windows overlap a bottom/visible Dock. Interestingly, the left-bottom window overlaps somewhat more than the right window.

  • With Monterey (macOS 12.3.1), if System Preferences > Dock & Menu Bar > Automatically hide and show the menu bar on desktop, then the left-bottom window overlaps the bottom/visible Dock.

These anomalies don’t effect me because I always use a left/autohide Dock and I never autohide the Menu Bar.

Thanks again, Peter.

1 Like