Skip to content

Instantly share code, notes, and snippets.

@skela
Created July 9, 2014 07:47
Show Gist options
  • Save skela/87cf62944fbfc23cb83c to your computer and use it in GitHub Desktop.
Save skela/87cf62944fbfc23cb83c to your computer and use it in GitHub Desktop.
Sample Code for "NSRightMouseDownMask Flag ignored for NSStatusItem sendActionOn"
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
self.statusItem.target = self;
self.statusItem.action = @selector(clickStatusItem:);
[self.statusItem sendActionOn:(NSLeftMouseDownMask|NSRightMouseDownMask)];
NSImage *img = [NSImage imageNamed:@"icon_empty"];
[img setTemplate:YES];
self.statusItem.image = img;
}
- (IBAction)clickStatusItem:(id)sender {
BOOL rightClick = (([[NSApp currentEvent] modifierFlags] & NSControlKeyMask) == NSControlKeyMask) || ([[NSApp currentEvent] type] == NSRightMouseDown);
if (rightClick) {
[self singleRightClickedStatusItem:sender];
} else {
[self singleLeftClickedStatusItem:sender];
}
}
-(IBAction)singleLeftClickedStatusItem:(id)sender {
NSLog(@"Left Clicked Status Item");
}
-(IBAction)singleRightClickedStatusItem:(id)sender {
NSLog(@"Right Clicked Status Item");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment