How can I get installed apps in mac os x programmatically either through C code or Objective-C code?
Asked
Active
Viewed 4,483 times
2
-
that is ls command in terminal . I want to get list of installed apps programmatically – pavanmvn Jun 18 '14 at 08:46
-
do u want the list of apps only in ur Applications folder? or all the .app files in ur mac? – Shanti K Jun 18 '14 at 08:47
-
Is it possible to get all .app files in mac ? – pavanmvn Jun 18 '14 at 08:49
-
yes it is. check the answer.. – Shanti K Jun 18 '14 at 09:15
1 Answers
5
It is possible to get all the app files using the spotlight API. Specifically, NSMetadataQuery class..
-(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]);
}
}
You have various other attributes, such as kMDItemFSName
. More attributes can be found here
The terminal version of the above is:
mdfind 'kMDItemKind=Application'

Shanti K
- 2,873
- 1
- 16
- 31
-
-
Looks like `kMDItemKind ` is localized. I had success with `"kMDItemContentType == 'com.apple.application-bundle'"` – ManuelSchneid3r Nov 08 '21 at 05:41