#import "IPMenulet.h" @implementation IPMenulet -(void)dealloc { [statusItem0 release]; [statusItem1 release]; [statusItem2 release]; [statusItem3 release]; [statusItem4 release]; [super dealloc]; } - (void)awakeFromNib { NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSString *path = [bundle pathForResource:@"window" ofType:@"tif"]; DeskIcon = [[NSImage alloc] initWithContentsOfFile:path]; path = [bundle pathForResource:@"menu" ofType:@"tif"]; MenuIcon = [[NSImage alloc] initWithContentsOfFile:path]; statusItem4 = [[[NSStatusBar systemStatusBar] statusItemWithLength:26] retain]; [statusItem4 setHighlightMode:YES]; [statusItem4 setEnabled:YES]; [statusItem4 setToolTip:@"Space4"]; [statusItem4 setTitle:[NSString stringWithString:@""]]; [statusItem4 setImage:DeskIcon]; statusItem3 = [[[NSStatusBar systemStatusBar] statusItemWithLength:26] retain]; [statusItem3 setHighlightMode:YES]; [statusItem3 setEnabled:YES]; [statusItem3 setToolTip:@"Space3"]; [statusItem3 setTitle:[NSString stringWithString:@""]]; [statusItem3 setImage:DeskIcon]; statusItem2 = [[[NSStatusBar systemStatusBar] statusItemWithLength:26] retain]; [statusItem2 setHighlightMode:YES]; [statusItem2 setEnabled:YES]; [statusItem2 setToolTip:@"Space2"]; [statusItem2 setTitle:[NSString stringWithString:@""]]; [statusItem2 setAction:@selector(test2:)]; [statusItem2 setDoubleAction:@selector(test2:)]; [statusItem1 setTarget:self]; [statusItem2 setImage:DeskIcon]; statusItem1 = [[[NSStatusBar systemStatusBar] statusItemWithLength:26] retain]; [statusItem1 setHighlightMode:YES]; [statusItem1 setEnabled:YES]; [statusItem1 setToolTip:@"Space1"]; [statusItem1 setTitle:[NSString stringWithString:@""]]; [statusItem1 setAction:@selector(scriptTest:)]; [statusItem1 setTarget:self]; [statusItem1 setDoubleAction:@selector(scriptTest:)]; [statusItem1 setImage:DeskIcon]; statusItem0 = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; [statusItem0 setHighlightMode:YES]; [statusItem0 setEnabled:YES]; [statusItem0 setToolTip:@"SpacesControl"]; [statusItem0 setMenu:theMenu]; [statusItem0 setTitle:[NSString stringWithString:@""]]; [statusItem0 setImage:MenuIcon]; [DeskIcon release]; [MenuIcon release]; } -(IBAction)test2 { int iResponse = NSRunAlertPanel(@"Close Document", @"Are you sure you want to close the document?", @"OK", @"Cancel", /*ThirdButtonHere:*/nil /*, args for a printf-style msg go here */); switch(iResponse) { case NSAlertDefaultReturn: /* user pressed OK */ break; case NSAlertAlternateReturn: /* user pressed Cancel */ break; case NSAlertOtherReturn: /* user pressed the third button */ break; case NSAlertErrorReturn: /* an error occurred */ break; } } -(IBAction)scriptTest:(id)sender { NSDictionary* errorDict; NSAppleEventDescriptor* returnDescriptor = NULL; NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource: @"\tell application \"System Events\" to keystroke \"1\" using control down"]; returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; [scriptObject release]; if (returnDescriptor != NULL) { // successful execution if (kAENullEvent != [returnDescriptor descriptorType]) { // script returned an AppleScript result if (cAEList == [returnDescriptor descriptorType]) { // result is a list of other descriptors } else { // coerce the result to the appropriate ObjC type } } } else { // no script result, handle error here } } @end