How to find multiple apps with same bundle identifier?

北城以北 提交于 2019-11-30 20:25:53

This question was asked in 2012 concerning OS X Lion 10.7. As of OS X Yosemite 10.10 the answer is:

LSCopyApplicationURLsForBundleIdentifier

Summary:

Given a bundle identifier (such as com.apple.finder), find all URLs to the corresponding application.

Discussion:

Returns zero or more URLs to applications that have the specified bundle identifier.

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).

Another alternative is to use LSCopyApplicationURLsForURL to find all copies of all applications that handle a specific URL scheme. This does require the application to define a URL scheme however.

For example, you could find all email applications that handle the 'mailto' scheme, even if there are multiple versions of the same app on the system.

This is the only way I know to get all applications, instead of what the system considers the 'default' or 'preferred' application returned with other calls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!