Several years ago, I developed a status menu application in Objective-C. And I'm developing a new one in Swift. I have some lines of code in AppDelegate to show a status menu (NSMenu).
And I see Command H in the status menu. If I press Command H, the application won't call showHome()
class AppDelegate: NSObject, NSApplicationDelegate {
// MARK: - Variables
var statusItem = NSStatusItem()
// MARK: - IBOutlet
@IBOutlet weak var statusMenu: NSMenu!
func applicationWillFinishLaunching(_ notification: Notification) {
makeStatusMenu()
}
func makeStatusMenu() {
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
if let img = NSImage(named: "StatusMenuImage") {
statusItem.image = img.resize(w: 18.0, h: 18.0)
}
statusItem.menu = statusMenu
let showHomeMenuItem = NSMenuItem(title: "Show Home", action:#selector(showHome), keyEquivalent: "h")
statusMenu.addItem(showHomeMenuItem)
}
@objc func showHome() {
}
}
What am I doing wrong?
Thanks.