0

I was wondering if someone could help me out with a bit of syntax.

I have a menu bar app that I would like to run a function then the icon is clicked.

I have tried messaging about with this syntax with left click right click but it first runs the function and dent open the menu. Is there a way to make it run the function as well as open the menu at the same time?

Miles

Miles.Kelly
  • 101
  • 9
  • 2
    1. What exactly is your question? 2. What have you tried so far? 3. Where are you stuck? 4. Post code. – LinusGeffarth Aug 08 '17 at 17:04
  • Basically I would like to be able to run a function when the Menu bar button of the app is clicked on. I have been using this as a basic guide for my code https://stackoverflow.com/questions/33257848/left-vs-right-click-status-bar-item-mac-swift-2 However when I first click on the menu bar button it will run the function without opening the menu, then if i click it again it will open the menu. I would like it to open the menu and run the function, is that possible? – Miles.Kelly Aug 09 '17 at 08:13
  • use multi threading. you can run multiples process at one time...you can use this DispatchQueue.main.async {your code } – Subhojit Mandal Aug 10 '17 at 10:02
  • How would I do that? Inside the applicationDidFinshingLaunching i am stating func applicationDidFinishLaunching(_ aNotification: Notification) { if let button = statusItem.button { button.image = NSImage(named: "myImage") statusItem.menu = statusMenu queryState() } Where queryState is a function to check the state of the screen and the collect the output from the pipe as a string – Miles.Kelly Aug 11 '17 at 13:55

0 Answers0