Building and Deploying a Mac Menu Bar Application

Updated for Xcode 12 and Big Sur

The macOS Menu Bar in Big Sur

The macOS menu bar is often one of the most underutilized parts of the Mac operating system. Located at the top right of your computer screen, it consists of a set of easily accessible icons that can improve your productivity. While the default icons control things like volume or wifi connection, it is also possible to built custom applications for the menu bar. When I was creating one recently, I experienced difficulty finding articles that addressed how to do this in Apple’s latest macOS version (Big Sur). Additionally, there was limited information about building and distributing a complete Menu Bar Application. Today, I’ll walk you through the full process of creating a macOs Menu Bar application, all the way from setup to deployment. We will use Xcode, Swift, and SwiftUI to build the application.

My own Mac Menu Bar Application
This article as inspired by a simple Menu Bar application I built recently called the Mac API Tool. The application is a tool for developers to perform simple web requests when exploring APIs and testing endpoints used in their code. You can check it out and download it in the GitHub repository here. You may find some of the code there helpful for understanding how to create your own macOS menu bar application.

The Mac API Tool UI (first release)

Creating Your Application

First, you will want to create your application. To do this, open Xcode and click ‘Create a new Xcode project.’ On the resulting screen, go to the section for macOS templates and choose ‘App.’ Click next and you will arrive at an important screen, which you can see below.

This screen shows after you choose your project template

The key things to select here are the SwiftUI Interface and the AppKit App Delegate Life Cycle. You will also want to set your Product Name, team (if you have one), and organization identifier. Click “Next” and you will be prompted to choose a folder/location for your project. If you are planning on keeping this project in a repository, I suggest creating a repository on GitHub in advance and cloning it to your computer. You can then select it as the location for your project and easily manage your project using git.

Creating The Menu Bar Item

You are now ready to create the status bar item for your application! For this part of the process, I was able to get a large part of the implementation information from a great article by Aaron Wright, which you can find here. You can also check the repository I linked earlier for the menu bar application I recently created if you want to see some functional code. Since the main focus of this article is how to properly create, build, and deploy the application, I will only summarize the status bar item code here.

The code to turn this into a menu bar application is inside of AppDelegate.swift. You will want to open that file and remove all of the code in the applicationDidFinishLaunching function. Inside of that function, you will define a variable to hold your main content view and an NSPopover() object to serve as the window that opens when the application’s menu bar icon is clicked. You will create an NSStatusBar.system.statusItem() object and assign a button to it. This button will show and hide your popover when the menu bar icon is clicked. Again, refer to Aaron Wright’s article above or my project’s linked repository for this code.

Creating the Menu Bar Icon
In the code referenced above, you’ll notice the use of an NSImage named “Icon.” This can be created inside the Assets.xcassets folder within your project. Here, create a new Image Set and name it ‘Icon.’ Change the following settings to have these values for the image set.
1. Render As: Template Image
2. Devices: Deselect Universal, select Mac
3. Scales: Single Scale
Now, you can add your icon to the single spot available in the Image Set. I find that 16 x 16 px is usually a great size.

Disabling the Normal Application Window
Now, we have to disable the normal application window to make sure this application is only in the menu bar. To do this, open up Info.plist, add a setting for “Application is agent (UI Element)” and set it to “YES.”

Add this setting inside of Info.plist

Now, you can build and run your application, it should properly appear in the menu bar and is ready for you to begin implementation!

Deploying Your Application

Now that you’ve developed your application, its time to build and distribute a finished version of it. Below are the steps to help you do this.

Making the Application Easy to Uninstall
One unique problem I found with creating a Menu Bar application came when trying to uninstall it. After creating a build and running it, the application properly appears and stays in the menu bar. However, uninstalling it yields an error since the application is still open. Usually, you could click the app’s icon in the dock at the bottom of your screen to quit the application but we prevented that icon from showing up earlier when we edited Info.plist.

A simple fix for this is to provide the user with an option in the UI to quit the application. Then, if the user does want to uninstall your application, they can click the quit button and then uninstall like normal. This is much simpler than having to dig through their Activity Monitor to kill the relevant processes to quit the application. Below is a simple bit of SwiftUI code that you can use for your button.

Button(action: {
}) {
Text(“Quit App”)

Creating an Archive/Build of the Application
Note that if you want to share your application with others, you have to join the Apple Developer Program. To deploy your application, you first want to make sure you have the proper settings in the project settings. Navigate to the project’s general settings. Be sure to choose an app category, Bundle Identifier, Version Number, Build number, Deployment Target, Main Interface, and your App Icon (note: this is different from the icon you made earlier for the menu bar). You can see what this looks like below.

Configure these settings in your project’s settings

Now, to create a distributable version of your app, select Product > Archive within Xcode. The following window will pop up.

The Xcode archives window.

From this window you will select your new archive, and click Distribute App. In the next window, select “Developer ID.” Click next and then select “upload” to get your application notarized by Apple. This will take a few minutes and then you will be able to choose a location to save the distributable version of your app. You will now find a build of your app in the selected location. Move this into your Mac’s Applications folder and run it. Your app should now be working!

Releasing Your App Outside of The App Store
Apple has numerous release options for your application which you can check here. However, you may want to distribute your application outside of the App Store. I’ve found that the best way to do this is to perform a GitHub release. The application build you made in the last section can be uploaded to GitHub as a release of your repository. From there, others will be able to download and install your application in seconds!

You’ve just created your first macOS Menu Bar Application! I hope this tutorial was helpful for navigating the process. Feel free to ask questions and/or leave a comment. I’ve also provided a list of the resources referenced in this article below for you to use.

Mac API Tool: Use this resource to either download the application I created or to check the code in AppDelegate.swift to learn how to create the menu bar item for your application.
2. Aaron Wright’s Article: This is a great article with code related to AppDelegate.swift. It helped me when creating my own application and is definitely worth a read.
3. Apple’s Distribution Options: Check out this article to learn about the different ways to distribute your application.

Computer Science and Business Administration Student @ USC | Backend Developer @ Discotech | Passionate about Software Engineering

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store