Get MacOS menubar size in Swift

To get menubar size, we can call.

let menuBarHeight = NSStatusBar.system.thickness

That is returning 24 and it is the same as my external screen. I did command + shift + 5 and use the screen capture tool to rougly measure the size of menubar. It is roughly 24px.

However, for my macbook pro 14 inches m2 pro. The menubar seem thicker because of the webcam. Is there a way to find out the size in Swift?

You'll need to access the main screen via NSScreen and then check the top safeAreaInsets. This will be in screen coordinates, of course.

Thanks! Just tried that solution. I am getting 34. Using same method to measure, it is the height of the notch. Unfortunately, the menubar seems a little taller than the notch. I measured 37px and i can see the additional pixel with my eye when the menubar is not black.

This one is very close!

Get MacOS menubar size in Swift
 
 
Q