Q: Command line tool to print out path of an app I need to know the path of Xcode.app. Spotlight knows where to find .apps, so there is a system on MacOS to find such things. Is there a command line tool that would provide this information e.g.:
$ tool Xcode
/Applications/Xcode.app


A: Access the Spotlight database from the command line, searching for applications named "Xcode":
mdfind "kMDItemDisplayName==Xcode&&kMDItemKind==Application"

To view the Spotlight metadata for a given file or folder, use mdls, e.g. mdls /Developer/Applications/Xcode.app.

Alternatively, you can use AppleScript to get the path if Xcode is running.
tell application "System Events"
    tell application process "Xcode"
        set a to application file
        POSIX path of a
    end tell
end tell


A: try this:
sudo find / -name 'Xcode'

you can also use regex in the name of the thing you're looking for if you're using quotes.

A: If the app is somewhere on your path, you can use 'type':
jrobert$ type g++
g++ is /usr/bin/g++

Otherwise you'll need to use 'find' (or one of the several OS-X file-finders).
