Search code examples
objective-cbundleidentifier

Objective C: How to get another application's bundle identifier


I would like to get the bundle identifier of an application, given it's path.

eg:

NSString* vlcFilePath =  @"/Applications/VLC.app"

I know how to get the bundle identifier using NSWorkspace if it is the active application, but in this case it is not necessarily the active application.


Solution

  • NSBundle has a bundleIdentifier method. This won't run or load the application if it is not already loaded/running:

    NSString *vlcFilePath = @"/Applications/VLC.app";
    
    NSBundle *bundle = [NSBundle bundleWithPath:vlcFilePath];
    
    NSLog (@"%@", [bundle bundleIdentifier]);