System tray menu in MAC OS x application

1. Open interface builder create NSMenu from Tools->Library. And create NSMenuItem “Active” and “Quit”.
2. “Active” select “Sent Action” -> “Window Server” and select “deminiature” action.
3. “Quit” select “Sent Action” -> “Application” and select “terminate” action.
4. “Menu” select “Outlet” ->ServerControll (applcation name control)
5. In “ServerController.h” file
IBOutlet NSMenu *menu;
NSStatusItem *statusItem;
NSImage *statusImage;
NSImage *statusHightlightImage;
6. In “ServerController.m” file
//Used to detect where our files are
NSBundle *bundle = [NSBundle mainBundle];
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setEnabled:YES];
[statusItem setMenu:menu];
[statusItem setHighlightMode:YES];
[statusItem setToolTip:@”KB Keys”];
statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@”appicon” ofType:@”png”]];
[statusItem setImage:statusImage];
statusHightlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@”hoverappicon” ofType:@”png”]];
[statusItem setHighlightMode:YES];
[statusItem setAlternateImage:statusHightlightImage];

Share