objective-cmacoslaunch-services

Searching multiple apps with same bundle ID


I am trying to search for applications installed on my mac with a certain bundle ID. I manage to do this using LSFindApplicationForInfo found in this question.

The problem I am facing is that I can't figure out how I can search for installed applications that have the same bundle ID. E.g. if I have two versions installed of com.domain.coolapp, how can I list both? I can't seem to find any solution, other than searching for .app files using lsregister.

As stated in the docs, this is not possible using LSFindApplicationForInfo:

If more than one application is found matching the specified characteristics, Launch Services chooses one in the same manner as when locating the preferred application for opening an item.


Solution

  • You can use NSTask to call mdfind(1) (essentially Spotlight).

    mdfind "kMDItemCFBundleIdentifier == 'com.domain.coolapp'"
    

    It returns one matching app per line instead of only the preferred one, and on my machine the call returns instantaneously from the command line so there's likely something clever happening behind the scenes.