You can do something like this to find a single app by Bundle ID with AppleScriptObjC:
use framework "Foundation"
use scripting additions
set appBundleID to "com.barebones.bbedit"
set nsWS to current application's NSWorkspace's sharedWorkspace()
set appURL to nsWS's URLForApplicationWithBundleIdentifier:appBundleID
Is there a neat trick to finding ALL apps on a startup-disk that have that Bundle ID?
I 'spect I can make do with Spotlight if necessary.
use script "Metadata Lib" version "2.0.0"
set thePaths to perform search in folders {path to startup disk} predicate string "kMDItemCFBundleIdentifier == 'com.barebones.bbedit'"
To follow up on this: i just found out that mdfind isn’t 100% reliable.
A user recently informed me that mdfind couldn’t find his InDesign installations by the bundle identifier com.adobe.InDesign. After further testing, we found out that mdfind couldn’t find other Adobe apps either - and most likely any other app as well.
Switching to LSCopyApplicationURLsForBundleIdentifier solved the issue.
Absolutely. It relies on the Spotlight index being turned on, up-to-date and uncorrupted, and the volume you’re searching supporting it. But that’s not really a bug (apart from any corruption, perhaps) — it’s the way Spotlight works. It’s not 100% — but barring unsupported volumes, it tends to be either 100% or 0%.
It’s also possible for the Launch Services database to become corrupted — and in that case LSCopyApplicationURLsForBundleIdentifier will also be unreliable.