Simulate StatusItemHandler?

Hi,
Is it possible to programatically execute an NSStatusBar’s StatusItemHandler?
I need to perform exactly the same thing, as if the StatusItem icon in the OS X menubar was clicked.

Thanks.

Well, you can call from handler some method and you can call the same method in code…

Tried that already :frowning:

Code in a method called ShowStatusImage:

[code] // DISPLAY THE NSSTATUSITEM IN THE OS X MENUBAR
dim bar as NSStatusBar = NSStatusBar.SystemStatusBar
item1 = bar.CreateStatusItem(NSStatusBar.NSVariableStatusItemLength, AddressOf StatusItemHandler)
item1.highlightMode = true
item1.Image = NSStatusItemImage
item1.AlternateImage = NSStatusItemImage

item1.menu = nil
item1.Action=Cocoa.NSSelectorFromString(“menuAction:”)[/code]

Code in a method called StatusItemHandler:

[code] // DETERMINE THE POSITION OF THE NSSTATUSITEM
soft declare function frame lib CocoaLib Selector “frame” (obj_id as ptr) as Cocoa.NSRect
soft declare function valueForKey lib CocoaLib selector “valueForKey:” (obj_id as ptr, key as CFStringRef) as ptr

dim rect as Cocoa.NSRect = frame(valueForKey(item1,“window”))

// SET THE POPOVER COORDINATES
StatusPopoverWindow.left = rect.x+rect.w/2-StatusPopoverWindow.width/2
StatusPopoverWindow.Top = 20[/code]

When I call:

StatusItemHandler()

from the app.open event, I get the following error message: This method requires more parameters than were passed.

I also tried calling like this:

StatusItemHandler(item1)

But the I get a different error message: Paramaters are not compatible with this function??

I think StatusItemHandler from MacOSLib takes an NSMenuItem as the parameter. If you’re not using the value in the method, you can pass nil, otherwise you could make a new NSMenuItem to pass in… If you mouse over StatusItemHandler you should see the method definition “StatusItemHandler(hitItem as NSMenuItem)”

Thanks Jim - the parameter of nil did the trick !

Thank you very much.