Search code examples
c++objective-cmacosbundle-identifiercfbundleidentifier

How to check, where an application is located under OS X?


How to check the location of an application installed under OS X? I tried it with the method LSFindApplicationForInfo and it works fine if you are searching for the bundle identifier.

But this way is not working if you have installed more than one instances of an app. LSFindApplicationForInfo just gets the location of one instance of an app. Furthermore this function is deprecated in OS X 10.10.

The terminal input mdfind "kMDItemCFBundleIdentifier from the following thread works fine, but it just works if spotlight is enabled.

How to get the locations off all app instances with the same bundle identifier or the same name "name.app" inside source code written in C or Objective-C?

How to find multiple apps with same bundle identifier?

Check if a Mac OS X application is present


Solution

  • If you can target 10.10 or later, you can use LSCopyApplicationURLsForBundleIdentifier(). This is documented as returning the URLs of all applications with the given bundle identifier.

    It's not clear to me if the app you're attempt to find is one whose properties you control. If it is and you need to support versions of OS X prior to 10.10, one approach you can use is to make the target app claim to support a custom dummy URL scheme. Then you can use LSCopyApplicationURLsForURL() to find all instances of it. You construct a URL with your dummy scheme, such as com-yourcompany-yourproduct-app-identifier-scheme://junk and pass that as input.