Skip to content

Instantly share code, notes, and snippets.

@iafonov
Created November 2, 2009 17:01
Show Gist options
  • Save iafonov/224275 to your computer and use it in GitHub Desktop.
Save iafonov/224275 to your computer and use it in GitHub Desktop.
-(void)createStatusItem
{
statusItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength]
retain];
[statusItem setHighlightMode:YES];
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"icon" ofType:@"png"];
menuIcon= [[NSImage alloc] initWithContentsOfFile:path];
[statusItem setTitle:[NSString stringWithString:@""]];
[statusItem setImage:menuIcon];
[statusItem setEnabled:YES];
[statusItem setAction:@selector(popMenu:)];
[statusItem setTarget:self];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(applicationDidActivate:) name:NSApplicationDidBecomeActiveNotification object:app];
}
-(IBAction)showMenu:(id)sender
{
NSLog(@"showMenu");
[statusItem popUpStatusItemMenu:loggedInMenu];
}
-(IBAction)applicationDidActivate:(id)sender
{
[self showMenu:self];
}
-(IBAction)popMenu:(id)sender
{
NSLog(@"popMenu");
if ([app isActive]) {
[self showMenu:self];
} else {
[app activateIgnoringOtherApps:YES];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment