Adding to OS X Status Tray


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. @interface Tray : NSObject <NSApplicationDelegate> {
  2. NSStatusItem *trayItem;
  3. }
  4. @end
  5.  
  6. @implementation Tray
  7.  
  8. - (IBAction)testAction:(id)sender;
  9. {
  10. NSLog(@"Hello World");
  11. }
  12.  
  13. - (IBAction)quitAction:(id)sender;
  14. {
  15. [NSApp terminate:sender];
  16. }
  17.  
  18. - (void)applicationDidFinishLaunching:(NSNotification *)note;
  19. {
  20. NSZone *zone = [NSMenu menuZone];
  21. NSMenu *menu = [[[NSMenu allocWithZone:zone] init] autorelease];
  22. NSMenuItem *item;
  23.  
  24. item = [menu addItemWithTitle:@"Testing" action:@selector(testAction:) keyEquivalent:@""];
  25. [item setTarget:self];
  26.  
  27. item = [menu addItemWithTitle:@"Quit" action:@selector(quitAction:) keyEquivalent:@""];
  28. [item setTarget:self];
  29.  
  30. trayItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain];
  31. [trayItem setMenu:menu];
  32. [trayItem setHighlightMode:YES];
  33. [trayItem setTitle:@"HERE"];
  34. }
  35.  
  36. - (void)dealloc;
  37. {
  38. [trayItem release];
  39. [super dealloc];
  40. }
  41.  
  42. @end
  43.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.