Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find multiple apps with same bundle identifier?

Does anyone know of a good way to find (in the filesystem) every app with a given bundle identifier? NSWorkspace and Launch Services let you look for an app by bundle identifier, but only return a single result. I suspect Spotlight (NSMetadataQuery) might help, but I'm a bit unclear on its API, so I'm not sure if there's an appropriate key.

There's the command-line lsregister tool (inside LaunchServices.framework), which can be told to (re)register everything on the system and then dump a report on everything it knows about. Relying on that seems less than ideal, since it's undocumented and parsing its output could be a pain.

(Background: I'm building an app for game modding, and want to provide UI for quickly choosing from a short list of supported games rather than requiring the user to dig through the whole filesystem in an Open panel. However, I expect it's quite likely for a user to have multiple copies of a game installed: release and beta, extra copies for modding, etc.)

like image 628
rickster Avatar asked Jan 12 '12 19:01

rickster


People also ask

Can 2 apps have the same bundle ID?

A bundle ID or bundle identifier uniquely identifies an application in Apple's ecosystem. This means that no two applications can have the same bundle identifier.

What is difference between app ID and bundle ID?

A bundle ID precisely identifies a single app. A bundle ID is used during the development process to provision devices and by the operating system when the app is distributed to customers. Whereas, An app ID is a two-part string used to identify one or more apps from a single development team.

Is bundle ID visible in app store?

To locate the Apple bundle ID: Click the relevant app. Go to General > App Information. The Bundle ID is displayed.


1 Answers

You want the kMDItemCFBundleIdentifier Spotlight/metadata key.

pierre$39> mdfind "kMDItemCFBundleIdentifier == 'org.videolan.vlc'"
/Applications/VLC.app
/Applications/vlc-0.8.6c/VLC.app

From there it should just be a matter of making the right calls to the file metadata APIs (pick your poison, Carbon or Cocoa). Interestingly enough, this key is not very well documented: it is not in File Metadata Attributes Reference, though it is in MDItem Reference.

Once again, it goes to show that game modding tools raise use cases few other kind of apps raise, and that sometimes aren't very well served by Apple… </soapbox>

Addendum: once you have your list, in my opinion the best way to present it to the user would be to list the version (kMDItemVersion) of each item you found; you might also show the path, but the version is likely going to be the most useful thing to the user (after all, he likely keeps different instances in order to have specific versions).

like image 60
Pierre Lebeaupin Avatar answered Oct 13 '22 01:10

Pierre Lebeaupin