Reputation: 1295
Is it possible to check whether or not a system item is visible in the status bar on OSX, i.e. the Bluetooth icon?
Has anyone tried doing this before? No mentions on the documentation what so ever.
Upvotes: 2
Views: 79
Reputation: 285180
The paths of the active menu bar items are listed in ~/Library/Preferences/com.apple.systemuiserver.plist
You can check this way
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);
or using 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);
Upvotes: 2