Mac NSStatusItem how i can setAction and show menu ?

artbeat.easy

macrumors newbie
Original poster
Jul 1, 2010
18
0
Hello all )
I have some problem
if i set Action on NSStatusItem i can't show menu ((

NSStatusItem*statusItem …

[statusItem setMenu:…]
[statusItem setAction:…]

not work (( how i can handle click and show menu ?
 

artbeat.easy

macrumors newbie
Original poster
Jul 1, 2010
18
0
You can't. You can do one or the other, not both.

From the NSStatusItem reference doc for setMenu:
When set, the receiver’s single click action behavior is not used.
ok ( how i can handle menu open ? or how i can show menu ? if i handle mouse click ( setAction ) i can show menu manual ?
 

LinusR

macrumors 6502
Jan 3, 2011
286
293
ok ( how i can handle menu open ? or how i can show menu ? if i handle mouse click ( setAction ) i can show menu manual ?
Put in your method to call while clicking on the status item this code:
Code:
[theStatusItem popUpStatusItemMenu:theStatusMenu]
So for example:
Code:
- (void) awakeFromNib{
    statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
	
    [statusItem setAction:@selector(statusItemClicked)];
    [statusItem setTarget:self];
}

- (void)statusItemClicked {
    [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(showMenu) userInfo:nil repeats:NO];
    [NSApp activateIgnoringOtherApps:YES];
    
    [statusItem popUpStatusItemMenu:statusMenu];
}
Hope that helps.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.