Loading...

How to quit or close an app in macOS using Swift?

question macOS swift
Ram Patra Published on August 14, 2020

You can quit or exit an app with:

NSApp.terminate(self)

If you’re making a macOS menu bar app in Swift and have an option in the dropdown menu to quit the app then your code would look something like:

NSMenuItem(title: "Quit", action: #selector(quitClicked), keyEquivalent: "q")

Menu Bar Item

@objc private func quitClicked() {
    NSApp.terminate(self)
}

Function invoked when a user clicks on the menu item

Note: Do not forget to add @objc in front of the function so that it can be called from #selector.

Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

ToDoBar

Your to-dos on your menu bar.

Ram Patra Published on August 14, 2020
Image placeholder

Keep reading

If this article was helpful, others might be too

question macOS swift August 6, 2020 How to keep an app's window always on top of others in Swift?

Before launching the window, just use the appropriate window level, and you’re done.

question macOS swift August 6, 2020 How to open an app's window on top of all others in Swift?

You can open your app’s window on top of all other open application windows with the below code:

October 17, 2024 Show your screen and your face at the same time on macOS

In today’s world of remote work and digital content creation, engaging your audience has never been more important. Whether you’re giving a presentation, conducting a tutorial, or recording a demo, adding a personal touch can make all the difference. That’s where FaceScreen comes in. This innovative macOS app allows you to open up your camera view in Picture-in-Picture (PiP) mode, enabling you to show both your screen and your face simultaneously.