我想在 OS X 中状态栏菜单文本的左侧添加图标。我找不到在我的代码中实现此功能的示例代码。现在我正在使用代码来设置状态栏的图像(如下)和 IBActions 来调用 AppleScript 文件。
- (void)awakeFromNib {
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
NSBundle *bundle = [NSBundle mainBundle];
statusImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"wifi1" ofType:@"png"]];
statusHighlightImage = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"wifi2" ofType:@"png"]];
[statusItem setImage:statusImage];
[statusItem setAlternateImage:statusHighlightImage];
[statusItem setMenu:statusMenu];
[statusItem setHighlightMode:YES];
}
- (void)dealloc {
[statusImage release];
[statusHighlightImage release];
[super dealloc];
}
- (IBAction)RemoteAppleEvents:(id)sender {
NSString* path = [[NSBundle mainBundle] pathForResource:@"AppleEvents" ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];
[appleScript release];
}
- (IBAction)InternetSharing:(id)sender {
NSString* path = [[NSBundle mainBundle] pathForResource:@"WiFiShare" ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];
[appleScript release];
}
- (IBAction)BluetoothSharing:(id)sender {
NSString* path = [[NSBundle mainBundle] pathForResource:@"bluetooth" ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];
[appleScript release];
}
任何帮助,将不胜感激。谢谢!
更新*
我在 IB 中的下拉菜单
.