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 のドロップダウン メニュー
.