6

I am looking for a way to find an app's location on the system from the command line using its bundle identifier. I can open it like this:

open -b 'com.zerotier.ZeroTierOne'

... where com.zerotier.ZeroTierOne is my bundle ID, but what I want to do is locate where the app is actually installed. I want a command that will return (for example):

/Applications/ZeroTier One.app

in response to a query by identifier 'com.zerotier.ZeroTierOne'.

The "-R" option to open will reveal in finder but I want this to be completely non-interactive and done via a shell script.

17

The magic command is:

mdfind kMDItemCFBundleIdentifier = "com.zerotier.ZeroTierOne"

You can determine this by working backwards from mdls foo | grep kMDItemCF

So if you didn't know iPhoto's CF Bundle Identifier:

Mac:~ me$ mdls /Applications/iPhoto.app | grep kMDItemCF
kMDItemCFBundleIdentifier           = "com.apple.iPhoto"
3
  • Is there an equivalent API in Foundation for this? – mservidio Mar 9 '17 at 18:41
  • 1
    @mservidio I have answered that question on StackOverflow because it is programming-specific – Ben Leggiero Sep 4 '18 at 19:43
  • @AdamIerymenko (thanks for ZeroTier btw!) You don't need the extra pipe to grep: mdls -name kMDItemCFBundleIdentifier -raw "/Applications/Google Chrome.app" works. – luckman212 Oct 14 '20 at 3:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .