Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Height of the apple menubar

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.

like image 827
Samuel Avatar asked May 19 '10 16:05

Samuel


People also ask

How do I resize the menu bar on a Mac?

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.

What is Apple's menubar?

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.

How do I change the size of the menu bar on my Iphone?

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.

Can you customize the menu bar on Mac?

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 .


2 Answers

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
like image 190
Milos Avatar answered Sep 24 '22 04:09

Milos


Quick and simple Swift 5 solution:

NSStatusBar.system.thickness
like image 31
inexcitus Avatar answered Sep 22 '22 04:09

inexcitus