Challenge: Beep-Beep!

There isn’t a current solution to this challenge, so here’s my 2 cents.

In the AppDelegate.swift:

func applicationDidFinishLaunching(aNotification: NSNotification) { addWindowController() addResignActiveNotification() }

func applicationWillTerminate(aNotification: NSNotification) {
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.removeObserver(self)
}

func addResignActiveNotification() {

let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(
    self,
    selector: #selector(applicationInactive),
    name: NSApplicationDidResignActiveNotification,
    object: nil)

}

func applicationInactive(notification: NSNotification) {
NSBeep()
}

Since AppDelegate is already the Application’s delegate and in standard Cocoa objects a delegate is already registered as on observer for the methods it implements the only thing needed to make the beeping work is to add this function to AppDelegate:

func applicationDidResignActive(notification: NSNotification) {
    NSBeep()
}

And there was me feeling all smug.

In Xcode 9.0+, use NSSound.beep()