How to get all installed applications with Objective-C in OSX

I need to get all installed OSX application using lens c

I googled and found someone offering to do this with a terminal command:

I run this command on terminal

"system_profiler SPApplicationsDataType -xml"

to find all applications, but I can not get the terminal data from the code.

indicate how to get all installed applications, or at least please let me know in order to get the result of the terminal command from the lens c.

tone of thanks in advance

+1
source share
1 answer

NSFileManager /Applications.

NSArray *urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSLocalDomainMask];

NSError *error = nil;
NSArray *properties = [NSArray arrayWithObjects: NSURLLocalizedNameKey,
                       NSURLCreationDateKey, NSURLLocalizedTypeDescriptionKey, nil];

NSArray *array = [[NSFileManager defaultManager] 
                 contentsOfDirectoryAtURL:[urls objectAtIndex:0]
               includingPropertiesForKeys:properties
                                  options:(NSDirectoryEnumerationSkipsHiddenFiles)
                                    error:&error];
if (array == nil) {
    // Handle the error
}

Apple Doc:

NSFileManager https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html#//apple_ref/doc/uid/20000305-SW24

https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW25

+4

All Articles