How to find multiple applications with the same package ID?

Does anyone know a good way to find (in the file system) every application with a given package identifier? NSWorkspace and Launch Services let you search for an application by package ID, but return only one result. I suspect that Spotlight ( NSMetadataQuery ) may help, but I don't understand its API a bit, so I'm not sure if there is a corresponding key.

Here is the lsregister command line lsregister (inside LaunchServices.framework) that can be passed (re) to register everything on the system and then reset the report of everything that it knows. Based on this, it seems less ideal, since it does not document and analyze its output, there may be pain.

(Background: I am creating a game modding application and want to provide an interface for quickly selecting from a short list of supported games, instead of requiring the user to dig through the entire file system in the Open panel. Expect the user to have several copies of the installed game: release and beta, additional copies for modding, etc.)

+6
source share
3 answers

This question was asked in 2012 regarding OS X Lion 10.7. As for OS X Yosemite 10.10, the answer is:

LSCopyApplicationURLsForBundleIdentifier

Summary:

Given the bundle identifier (e.g. com.apple.finder), find all the URLs in the corresponding application.

Discussion:

Returns zero or more URLs for applications with the specified package identifier.

+4
source

You need the kMDItemCFBundleIdentifier Spotlight / metadata key.

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

From there, you just need to make the right calls to the file metadata API files (select your poison, carbon or Cocoa). Interestingly, this key is not well documented: it is not in the File Metadata Attributes Reference , although it is in the MDItem Reference .

Once again, it is shown that game modding tools increase the likelihood of using some other applications, and which are sometimes not well served by Apple ... </soapbox>

Addendum: after you have your own list, in my opinion, the best way to present it to the user is to list the version ( kMDItemVersion ) of each element you kMDItemVersion ; you can also specify the path, but the version is likely to be most useful to the user (after all, it probably supports different instances in order to have specific versions).

+7
source

Another alternative is to use LSCopyApplicationURLsForURL to find all copies of all applications that process a specific URL scheme. This requires the application to define a URL scheme.

For example, you can find all mail applications that process the mailto scheme, even if the system has several versions of the same application.

This is the only way to find out all the applications, and not that the system considers that the application "default" or "preferred" returns with other calls.

+1
source

Source: https://habr.com/ru/post/905855/


All Articles