Terminal: command to show application folder I recently discovered that I can open application from Terminal like this:

$ open -a TextEdit


Is there any command that would just show the application folder instead of opening it? Such that I could do this:

$ alias vmrun=\"`some-command 'VMware Fusion'`/Contents/Library/vmrun\"


I need that some-command to print the folder of VMware Fusion application.

UPDATE: I don't know where the application is installed, otherwise I could just hardcode it in the script
I have just created and uploaded a GitHub Gist GitHub Gist which may help you out.

The main functionality is:

function get_apps_folder () { 
    mdfind -0 -onlyin / \
        'kMDItemKind=="Application" &amp;&amp; kMDItemDisplayName="'"${1:-TextEdit}"'"' \
    | xargs -0 -I{} dirname {} 
}

function open_apps_folder () {
    open $(get_apps_folder "$1")
}


You could take that and add the two functions to your ~/.bash_profile and they would be available for any interactive shell sessions you are using. (And yes, getting around mixed and embedded single and double quotes can be messy.) :-)

But, to give a better explanation, the main part is:

mdfind -0 -onlyin / 'kMDItemKind=="Application" &amp;&amp; kMDItemDisplayName="VMware Fusion"' | xargs -0 -I{} open {}


The -onlyin /path limits the search to just the root volume, otherwise any “Spotlight-searchable” volume attached will most likely be searched as well, including Time Machine, which can get unwieldy and/or verbose, hence using -onlyin /. 

In the Gist, each line output by mdfind is fed to xargs which calls open on what is passed to it. Note that there is no particularly robust checking of what is passed to xargs (ie. it is assuming it is getting a directory).

mdfind and mdls can be pretty handy for things like this, although they can take a little getting used to. I usually use mdls /path/to/file to get an idea of what metadata that type of file has. I can then take those keys and values to search using mdfind. You can find a lot of pages, examples and documentation out there, BTW.