This example will help you get started (it's a menu app that allows you to open URLs)
1. Make sure you have the Xcode developer tools.
2. Create a new cocoa project.
3. In Interface Builder, create an instance of an NSMenu.
4. Edit the menu how you want it to look. (I set the font sizes two sizes less then standard)
5. Create a new subclass of NSObject.
6. Instantiate the class.
7. In the inspector, create actions for each menu item. Then create an NSMenu outlet.
8. Connect the menu items to their actions. Connect the outlet to the NSMenu instance.
9. Create files for the class you created.
10. Go back to Xcode.
11. Edit yourClass.m (or whatever you named it)
12. Right after the #import "yourClass.h", add this bit:
Code
@interface NSStatusBar (NSStatusBar_Private)
- (id)_init;
- (void)_insertStatusItem:(id)fp8 withPriority:(int)fp12;
- (id)_lockName;
- (id)_name;
- (void)_refreshWindows;
- (void)_removeStatusItem:(id)fp8;
- (void)_setLengthOfStatusItem:(id)fp8 to:(float)fp12;
- (void)_setUpdatesDisabled:(BOOL)fp8;
- (id)_statusItemWithLength:(float)fp8 withPriority:(int)fp12;
- (BOOL)_updatesDisabled;
@end
13. For each action, I used something like this:
Code
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"http://yoursite.com"]];
So each action would look like this:
Code
- (IBAction)centralAnnounce:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"http://yoursite.com/1"]];
}
Then, just before the @end line at the bottom of yourClass.m, I added this:
Code
- (void)awakeFromNib
{
NSStatusBar *systemStatusBar = [NSStatusBar systemStatusBar];
if ([systemStatusBar respondsToSelector: @selector(_statusItemWithLength:withPriority:)]) {
statusItem = [[systemStatusBar _statusItemWithLength: 28 withPriority: 8001] retain];}
[statusItem setHighlightMode:YES];
[statusItem setImage:[NSImage imageNamed:@"MenuIcon.tiff"]];
[statusItem setAlternateImage:[NSImage imageNamed:@"MenuIconAlt.tiff"]];
[statusItem setMenu:theMenu];
[statusItem setEnabled:YES];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isPastUser"]==NO)
{
[NSApp activateIgnoringOtherApps:YES];
int status;
status = NSRunAlertPanel(@"Welcome to myMenu",@"This is the first time you have launched myMenu. Would you like to set myMenu to start when you login? This is the only time this message will appear.",@"OK",@"No Thanks",nil);
if ( status == NSAlertDefaultReturn )
{
NSAppleScript *addScpt = [[NSAppleScript alloc]
initWithSource:@"tell application \"System Events\"\nif (count of (login items whose name is equal to \"myMenu\")) is not 0 then\nreturn \"Already installed\"\nend if\nset the_file to (file of application processes whose name is equal to \"myMenu\")\nif (count of the_file) is 0 then\nreturn \"Couldn't locate application\"\nend if\nend tell\n\nset the_path to POSIX path of first item of the_file\n\ntell application \"System Events\"\nmake new login item at the front of login items with properties {path:the_path}\nend tell"];
[addScpt executeAndReturnError:nil];
}
if ( status == NSAlertAlternateReturn )
{}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isPastUser"];
}
}
14. Edit Info.plist and InfoPlist.strings for version numbers, etc.
15. Add an application icon, add menu icons named "MenuIcon.tiff" + "MenuIconAlt.tiff".