Here's my simple code to search apps installed in specified directory, it works perfect before macOS 10.15.
After upgrade to the beta version of 10.15, many apps can't be found, is there any new security system affects
the behaviour?
#import
#import "Result.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
if (argc != 2) {
fprintf(stderr, "lsapp \n");
exit(1);
}
NSString* appName = [NSString stringWithUTF8String:argv[1]];
Result* result = [[Result alloc] init];
NSMetadataQuery* query = [[NSMetadataQuery alloc] init];
[query setSearchScopes: [NSArray arrayWithObjects:@"/Applications",
@"/Library",
NSMetadataQueryUserHomeScope,
nil]];
[query setPredicate:[NSPredicate predicateWithFormat:@"(kMDItemKind == 'Application')"]];
[[NSNotificationCenter defaultCenter] addObserver:result
selector:@selector(queryDidFinishGathering:)
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
[query startQuery];
CFRunLoopRun();
if (result.resultMap[appName]) {
printf("Found it!\n");
printf("%s", [result.resultMap[appName] UTF8String]);
} else {
printf("App is not exist!\n");
}
}
return 0;
}