Difference In MENUBARHEIGHT() Calculation When Retrieved ViaAppleScript

Hey @peternlewis, can you shed some light on why the MENUBARHEIGHT() calculaton returns a different number when it’s retrieved from Keyboard Maestro via AppleScript, as opposed to when it’s retrieved directly in the Keyboard Maestro Editor?

For instance, in the example screenshot below, the results shown in the KM Value Inspector is 24, but when that same calculation is retrieved via AppleScript, the result is 37.

FWIW, the results are the same no matter if I test on my MacBook screen or my external screen. Any insight is appreciated, thanks I advance!

AppleScript used to retrieve the calculation (click to expand/collapse)
tell application "Keyboard Maestro Engine" to set kmCalculation to calculate "MENUBARHEIGHT()"
Screenshot (click to expand/collapse)

That's an astounding question, which I cannot answer, but I will suspect that you can synchronize both if you return your display scaling to "Default." You probably moved the setting on your Mac to the left.

Actually, I have my MacBook resolution set to the default. The external monitor is set to 2560x1440... but I tested changing the resolutions and it doesn’t affect the outcome.

MacBook Screenshot (click to expand/collapse)

ASUS Screenshot (click to expand/collapse)

I ran the AppleScript on my M2 PowerBook with the notch in the menubar and got 37. I ran it on my 13-inch Intel PowerBook and got 0 (the menu bar is hidden). And I ran it on my 17-inch PowerBook and got 24.

I believe the notch results in a deeper menubar, which the AS correctly calculates. But the standard size has been 24 pixels up until the notch was introduced.

My question doesn’t pertain so much as to the menu bar’s actual height, but rather, why does the MENUBARHEIGHT() calculation report different results when it’s called directly from Keyboard Maestro, as opposed to when AppleScript calls for it via Keyboard Maestro. It’s still Keyboard Maestro that is performing the calculation, and simply passing it to the AppleScript... so the value should not change. Unless there is some underlying voodoo that I just don’t understand which is a very real possibility. :sweat_smile:

EDIT: Digging a littler deeper, there appears to be something else at play here. Note the discrepancies in the following test macro.

It appears the Value Inspector and real-time results shown in actions display 24, whereas the calculation does indeed calculate 37.

For example, in the screenshot, the variable action indicates that the variable will be set to 24, but in reality, it’s set to 37. The Value Inspector as well shows 24 as the menu bar height, but when it’s actually used in a macro (or passed to AppleScript), the result ends up being 37.

Screenshot (click to expand/collapse)

I'm not seeing that on my M2, where both approaches return 37:

Hmmm.... how.... odd.... let me check things when I disconnect my external monitor a little later.

EDIT: Does your Value Inspector also show 37?

Yes, sorry, neglected to include that. But everything was 37 and nothing showed 24 on a system that has a notch.

Keyboard Maestro’s MENUBARHEIGHT function returns the result of the system API:

[[[NSApplication sharedApplication] mainMenu] menuBarHeight]

Why it differs from AppleScript or which is accurate in which situations, I'm afraid I don't have answers for that.