2015-09-27 66 views

回答

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); 
+0

謝謝,這個工作了偉大的! –

相關問題