是否可以检查系统项是否在OSX的状态栏中可见,即蓝牙图标?
以前有人试过这样做吗?没有提到文件中的内容。
答案 0 :(得分:2)
活动菜单栏项的路径列在~/Library/Preferences/com.apple.systemuiserver.plist
你可以这样检查
NSURL *userLibraryURL = [[NSFileManager defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *systemUIServerPreferences = [userLibraryURL URLByAppendingPathComponent:@"Preferences/com.apple.systemuiserver.plist"];
NSDictionary *data = [NSDictionary dictionaryWithContentsOfURL:systemUIServerPreferences];
BOOL bluetoothIsInMenuBar = [data[@"menuExtras"] containsObject:@"/System/Library/CoreServices/Menu Extras/Bluetooth.menu"];
NSLog(@"%d", bluetoothIsInMenuBar);
或使用NSPredicate
NSURL *userLibraryURL = [[NSFileManager defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *systemUIServerPreferences = [userLibraryURL URLByAppendingPathComponent:@"Preferences/com.apple.systemuiserver.plist"];
NSDictionary *data = [NSDictionary dictionaryWithContentsOfURL:systemUIServerPreferences];
NSPredicate *bluetoothPredicate = [NSPredicate predicateWithFormat:@"SELF contains 'Bluetooth'"];
BOOL bluetoothIsInMenuBar = [[data[@"menuExtras"] filteredArrayUsingPredicate:bluetoothPredicate] count];
NSLog(@"%d", bluetoothIsInMenuBar);