Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Menubar application for Mac

People also ask

What is menubar on Mac?

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.

How do you make a menu on a 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 .


NSStatusItem is what you are looking for. Also add LSUIElement with string value of 1 to your Info.plist to hide it from Dock.


I've found Codebox's Popup to be a great starting point. It is ripe for forking on Github.

enter image description here

Though it works nicely, they do note on their site...

P. S. In Lion, Apple is adding a new class for popovers like in iOS. So, after OS X 10.7 is released, you would better to rely on native Cocoa classes where it is possible. In other cases, the Popup project should still be usable.


BitBar is an application on GitHub that can "Put anything in your Mac OS X menu bar".

It runs shell or other executable scripts (which it calls Plugins - see the many examples in the plugins repo) and displays the results in the menu bar. You can write your own plugin and have it run simply by adding it to the 'Plugins folder'. As well as displaying information, it can also run pre-defined bash scripts interactively from the plugin menus you define.

Since I first posted this answer it's popularity has exploded (52 contributors currently) and there is now even a distributable version with which you can package your own plugins.

A very simple (non-interactive) example to show live Bitcoin price:

enter image description here


As Apple added NSStatusBarButton property to NSStatusItem in Yosemite, we can implement menubar app a lot simpler. I just created a sample project on github.

https://github.com/taichino/PopupTest


FlyCut is another nice open source application that does this. (MIT licensed.) Very handy too, I use it several times a day.

Here's some code that seems like it may be relevant:

    // Flycut/AppController.h
    IBOutlet NSMenu *jcMenu;

    // Flycut/AppController.m
    statusItem = [[[NSStatusBar systemStatusBar]
            statusItemWithLength:NSVariableStatusItemLength] retain];
    [statusItem setHighlightMode:YES];

    if ( [[DBUserDefaults standardUserDefaults] integerForKey:@"menuIcon"] == 1 ) {
        [statusItem setTitle:[NSString stringWithFormat:@"%C",0x2704]]; 
    } else if ( [[DBUserDefaults standardUserDefaults] integerForKey:@"menuIcon"] == 2 ) {
        [statusItem setTitle:[NSString stringWithFormat:@"%C",0x2702]]; 
    } else {
        [statusItem setImage:[NSImage imageNamed:@"com.generalarcade.flycut.16.png"]];
    }
    [statusItem setMenu:jcMenu];
    [statusItem setEnabled:YES];