How to create a Menubar application for Mac

MacosCocoaMenubar

Macos Problem Overview


EDIT: This is a nice ready-made menubar application here (github source) by this answer.


I was wondering how to make a menubar application, what are the requirements for that to do so?

I saw a simple application for the menubar was to open links using your browser, I want to create something similar to that.

enter image description here

This is the application I like to make similar.

Macos Solutions


Solution 1 - Macos

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

Solution 2 - Macos

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.

Solution 3 - Macos

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

Solution 4 - Macos

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

Solution 5 - Macos

[FlyCut][1] 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];

[1]: https://github.com/TermiT/Flycut "Flycut on GitHub"

Solution 6 - Macos

Mail Notifr is another open source Menubar app. It helped me a bunch, especially when I needed to figure out how to implement the open on login. Also available on the App Store.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMacMacView Question on Stackoverflow
Solution 1 - MacosSteamTroutView Answer on Stackoverflow
Solution 2 - MacosAlex GrayView Answer on Stackoverflow
Solution 3 - MacosMatzFanView Answer on Stackoverflow
Solution 4 - MacostaichinoView Answer on Stackoverflow
Solution 5 - MacosfunrollView Answer on Stackoverflow
Solution 6 - Macoslindon foxView Answer on Stackoverflow