gpt4 book ai didi

macos - 检查状态栏中是否存在项目?

转载 作者:行者123 更新时间:2023-12-03 16:35:18 24 4
gpt4 key购买 nike

是否可以检查 OSX 状态栏中的系统项目是否可见,即蓝牙图标?

以前有人尝试过这样做吗?文档中没有提及任何内容。

最佳答案

事件菜单栏项目的路径在~/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);

关于macos - 检查状态栏中是否存在项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32807757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com