Wild8x
Wild8x

Reputation: 459

How to terminate programmatically a MacOS app when clicking on the top left red dot?

Good Day!

By default when we click on the top left red dot of our window app, the window closes but not the app and the menu bar stays displayed on top.

What I would like to achieve by code is to terminate (close) the app when we click on the red dot... by doing this the menu bar will disapears hence the app is terminated.

Thanks in advance for your help.

Upvotes: 1

Views: 1602

Answers (1)

Asperi
Asperi

Reputation: 257711

Add the following callback in your app delegate

class AppDelegate: NSObject, NSApplicationDelegate {

    //... other methods here

    func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
        return true
    }
}

Upvotes: 3

Related Questions