pav*_*mvn 2 macos objective-c .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 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]);
}
}
Run Code Online (Sandbox Code Playgroud)
您还有各种其他属性,例如kMDItemFSName. 更多属性可以在这里找到
上面的终端版本是:
mdfind 'kMDItemKind=Application'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3599 次 |
| 最近记录: |