Clickable status bar icon?

Hi,
I have the following code which correctly displays a status bar icon in the menu bar.

[code]// DEFINE AND DISPLAY THE NSStatusItem IN THE OS X MENUBAR
dim bar as NSStatusBar = NSStatusBar.SystemStatusBar
item1 = bar.CreateStatusItem(NSStatusBar.NSVariableStatusItemLength, AddressOf StatusItemHandler)

// DISALLOW HIGHLIGHTING
item1.highlightMode = False

// DEFINE THE DEFAULT IMAGE
item1.Image = new Cocoa.NSImage(retinaKit.imageNamed( “NSStatusItemImage” ).NSImageRef)

// DECLARE NO MENUITEMS
item1.menu = nil

// DEFINE THE EVENT HANDLER
item1.Action = Cocoa.NSSelectorFromString(“menuAction:”)[/code]

Can someone please advise me how I now make the status bar icon clickable?
I would like Window1 to display when the icon is clicked.

Thank you all in advance.

Maybe try MBS Examples?

you may want to check Action event there and call SendActionOn passing NSLeftMouseDownMask maybe?

Check this out: https://github.com/macoslib/macoslib/issues/83

Thanks Thomas, but I have absolutely no idea how to merge that with my example above?

Thanks anyway.

First you’ll have to modify MacOSLib’s NSStatusItem.Action and .Menu properties. Then, you can open your window in the StatusItemHandler.

The way I ended up doing it was to modify the setTarget method of NSStatusItem…

Add this

Target=target_id Action = Cocoa.NSSelectorFromString("menuAction:")

This sets the target and action of the statusItem, so if the menu is nil, it will fire on click. If there is a menu, the action of the StatusItem is never called.

Does the same as the link above, but in a default way where you don’t have to remember to set nil on the menu to get clicks.

Jim, do you mean simply add your line of code above, (exactly as-is) to the very bottom of my original code?
Or do you mean replace my last line of code with yours?

Thanks.

Ah, I misread your post Jim.

Now solved!
I simply added Jim’s 2 lines of code to the end of NSStatusItem’s setTarget method, as he suggested :slight_smile:

Thank you all so much!