A question similar to Locating bundles by identifier, but different problem:
I have several applications that need to locate each other's bundles by their ID. That always works well, unless I do a completely fresh install of all my applications. In many cases it's sufficient to point the finder to the install location for the bundle locations to be known, but sometimes even that's not enough; I have to run the application first before it's bundle ID can be used to find the path. I should mention that I am using an installer that copies the applications to the /Applications/, so the finder never opens when I install the apps.
It appears that when an application bundle is newly installed, it takes the system some time before some internal registry is updated that maps the bundle ID to the bundle location. What I would like to know is:
The mappings are maintained in the Launch Services database. I don't where this is stored, but the exact location is irrelevant, as there are better ways of achieving your goal.
You can manually update the Launch Services database in a number of ways, but personally, I think doing it programmatically would be easier, especially in your situation. In that case, you would utilize the Launch Services API—specifically, I'd look into using LSRegisterURL()
, since that seems to achieve what you want to do.
Take a look at the Launch Services documentation for more information about registering applications in the database and how this all works in general.
An alternative, in case you ever need one, would be to search using the Spotlight APIs with the kMDItemCFBundleIdentifier
key:
pierre$39> mdfind "kMDItemCFBundleIdentifier == 'org.videolan.vlc'"
/Applications/VLC.app
/Applications/vlc-0.8.6c/VLC.app
Spotlight is tightly integrated with the system, such that files/folders get indexed as soon as they are written to the filesystem, you should not have any issue of the app not having been indexed yet. Of course, you have to be ready to handle more than one response…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With