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.

Revisions

  1. skela created this gist Jul 9, 2014.
    27 changes: 27 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    - (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");

    }