I was just wondering how to get the height of the apple menubar, in pixels (the one always on top)
(My screen size is 1200 x 800) i was wondering what it would be excluding the menubar.
Go to System Preferences, Accessibility, Display, Display. Then look for Menu Bar Size and switch to Large. Then close System Preferences and it will ask you log out for the change to take affect.
The menu bar runs along the top of the screen on your Mac. Use the menus and icons in the menu bar to choose commands, perform tasks, and check status. You can set an option to automatically hide the menu bar so it's shown only when you move the pointer to the top of the screen. See Change Dock & Menu Bar preferences.
The menubar uses the system font and size which is not under any user control. You can reduce the screen's resolution which will cause all text to enlarge. You can also enable screen zooming through Accessibility preferences. Open the panel and select Zoom from the list.
On your Mac, use Dock & Menu Bar System Preferences to change the appearance of the Dock, and to select items to show in the menu bar and in Control Center. To change these preferences, choose Apple menu > System Preferences, then click Dock & Menu Bar .
As per @Ross's answer:
NSApplication.sharedApplication().mainMenu?.menuBarHeight
Unfortunately, this will return nil
before the app finishes launching (because the mainMenu
will be nil
). If you need this value earlier than that (and you don't want to guess it for the future OS releases), you can calculate it like so:
if let screen = NSScreen.mainScreen() {
let menuBarHeight = screen.frame.height - screen.visibleFrame.height - screen.visibleFrame.origin.y - 1
}
This number will not be correct only if there is some extra screen furniture (like the Dock for example) pinned from the top, which seems extremely unlikely.
Update: To support multiple displays (primary and secondary):
let appleMenuBarHeight = screen.frame.height - screen.visibleFrame.height - (screen.visibleFrame.origin.y - screen.frame.origin.y) - 1
Quick and simple Swift 5 solution:
NSStatusBar.system.thickness
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With