Objective c 如何以编程方式获取mac os x上已安装应用程序的列表
如何通过C代码或Objective-C代码以编程方式在mac os x中获取已安装的应用程序?使用spotlight API可以获取所有应用程序文件。具体来说,NSMetadataQuery类Objective c 如何以编程方式获取mac os x上已安装应用程序的列表,objective-c,macos,.app,Objective C,Macos,.app,如何通过C代码或Objective-C代码以编程方式在mac os x中获取已安装的应用程序?使用spotlight API可以获取所有应用程序文件。具体来说,NSMetadataQuery类 -(void)doAQuery { query = [[NSMetadataQuery alloc] init]; // [query setSearchScopes: @[@"/Applications"]]; // If you want to find applications on
-(void)doAQuery {
query = [[NSMetadataQuery alloc] init];
// [query setSearchScopes: @[@"/Applications"]]; // If you want to find applications only in /Applications folder
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"kMDItemKind == 'Application'"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:nil];
[query setPredicate:predicate];
[query startQuery];
}
-(void)queryDidFinishGathering:(NSNotification *)notif {
int i = 0;
for(i = 0; i< query.resultCount; i++ ){
NSLog(@"%@", [[query resultAtIndex:i] valueForAttribute:kMDItemDisplayName]);
}
}
这是终端中的ls命令。我想获取已安装应用程序的列表你想只在你的应用程序文件夹中获取已安装应用程序的列表吗?或者你的mac中的所有.app文件?是否可以在mac中获取所有.app文件?是的。检查答案。。
mdfind 'kMDItemKind=Application'