How do I know which applications are installed on OS X using Objective-C or Macruby?

Could you tell me which object and which method I can use to get information about installed applications on OSX with objective c or macruby?

+5
source share
6 answers

If you want to list all the graphical applications, you can use Launch Services . For a list of functions, see the link .

Do not manually list .app packages . This has already been done by the system, and you just need to request it. There is a command line program called lsregisterin

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister

. , , ,

+4

Apple system_profiler, .

% system_profiler SPApplicationsDataType

C Objective-C system() .

:

% man system

% man system_profiler

+3

OS X " ". OS X , Finder . , , / ~/ "".

, , , ".app" - . ( , , , ).

+2

:

  • system_profiler SPApplicationsDataType -xml . SPApplicationsDataType , . -xml , xml .

: Cocoa

:

NSStirng * commangString = @"system_profiler SPApplicationsDataType -xml"; 
NSData * resultData = [CommandLineTool runCommand:commangString];
NSArray * appArray = [PlistManager objectFromData:resultData];
// parse array of NSDictionaries here ....



// method from PlistManager
+ (id) objectFromData: (NSData *) data {
    NSString *errorString = nil;
    NSPropertyListFormat format;
    id object = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainers format:&format errorDescription:&errorString];
    if (!errorString) {
        return object;
    } else {
        NSLog(@"Error while plist to object conversion: %@", errorString);
        return nil;
    }
}

// runCommand method was used from post I mentioned before
+1

Spotlight NSMetadataQuery.

, , mdfind :

mdfind "kMDItemContentType == 'com.apple.application-bundle'"

.

0

Since this is a unix-like OS, there is no real way to tell what you installed (unless, of course, you control another application - then there are many ways to do this for obvious reasons).

Typically, applications fall into / Applications or ~ / Applications, but you can run them from anywhere, and not from these folders (as for a unix machine).

-1
source

All Articles