0

I Will do my best to explain. I'm currently creating a little tool that rests on the status bar of the mac, I want to enter in the setting of the tool by pressing right-click on the element shown on the status bar. Like this

Currently, I can open the application by clicking on the tool, but how do I open a menù setting with a right-click?

Until now this is the code that is opening the app

    import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate { //MAIN

    let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)


    func applicationDidFinishLaunching(_ aNotification: Notification) {// Insert code here to initialize your application
        statusItem.button?.title = "∞"
        statusItem.button?.target = self
        statusItem.button?.action = #selector(showSetting)
        let storyboard = NSStoryboard(name: "Main", bundle: nil) 
        let vc = storyboard.instantiateController(withIdentifier: "ViewController") as? ViewController

        vc?.automaticRefresh()
        vc?.beginning()
         }



    @objc public func showSetting() { //THIS IS NOT REALLY THE SETTING BUT JUST THE APPLICATION ITSELF 
        let storyboard = NSStoryboard(name: "Main", bundle: nil) //QUI VADO A FARE IN MODO DI POTER CHIAMARE IL MIO VIEW CONTROLLER
        let vc = storyboard.instantiateController(withIdentifier: "ViewController") as? ViewController
        let popoverView = NSPopover()
        popoverView.contentViewController = vc
        popoverView.behavior = .transient
        popoverView.show(relativeTo: statusItem.button!.bounds, of: statusItem.button!, preferredEdge: .maxY)
        vc?.printCurrentState()

    }
}
Willeke
  • 14,578
  • 4
  • 19
  • 47
  • Thanks for the response. That one helps with an action done with the right-click, but how can I open a setting menù like this https://i.stack.imgur.com/swpHy.jpg? – Daniele Ligato Mar 03 '20 at 19:21
  • See [Can I open an NSMenu programatically?](https://stackoverflow.com/a/51591669/4244136) – Willeke Mar 04 '20 at 09:47

0 Answers0