Screen Size Math

I either don't understand the MENUBARHEIGHT() function or I've encountered a bug.


Here's the macro I used to generate the values above.

Download: Screen Math.kmmacros (9.1 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.5 (23F79)
  • Keyboard Maestro v11.0.3

My assumption was that the two differences would be equivalent to MENUBARHEIGHT() (plus or minus a pixel). The third-party app I use to measure screen dimensions, PixelSnap 2, seems to confirm that the differences are correct.

Does anyone have insight on topic? Thanks in advance!

I don't think you've told us what you expected ?

1 Like

Thanks, @ComplexPoint; in the OP I added this...

1 Like

I think these values are affected by your scaling value as found in System Settings. If you use the correct scaling, there will be no difference between the two values:

1 Like

Hi, @Airy.

Do you mean anything except the Default present? If so, that's consistent with my testing, however, I still don't understand why there would be a discrepancy. After all, the other values are calculated properly. Why would this only affect MENUBARHEIGHT()? Maybe @peternlewis would know.

On my 16" M1 Max MacBook Pro (MacBookPro18,2)...

1168 x 755 Larger Text

1312 x 848

1496 x 967

1728 x 1117 Default

2056 x 1329 More Space


The resolution in my OP is 1728 x 1080. That's what I generally use because I don't like my display to render a notch.

I specifically didn't say which setting might work for you and your display, because I wasn't sure, but I suspected the "More Space" (max DPI) setting would have resolved the issue. Hopefully it would take you only a few seconds to try it.

OH, I see you did test it above. Sorry. I guess I'm out of ideas.

1 Like

On an Intel iMac:

image

...so you'll see your "default" is returning the correct (for your machine) numbers.

My guess is that a call to whatever system API returns the menubar height always gets back the default, unscaled, value while the other values include scaling.

1 Like

I'm afraid you'd have to ask Apple that.

The MENUBARHEIGHT function returns the result of the system API menuBarHeight. Specifically:

int(round([[[NSApplication sharedApplication] mainMenu] menuBarHeight]))

The documentation for the function says:

If called on the main menu, returns the height of the menu bar in pixels.

But I guess if what you want is the difference between the top of the screen and the top of the visible screen, use that equation.

2 Likes