Terminal: command to show application folder
Solution 1:
I believe this is what you're looking for:
alias vmrun=\"`osascript -e 'tell application "Finder" to get POSIX path of (application file id "com.vmware.fusion" as alias)'`/Contents/Library/vmrun\"
Now when I type vmrun
, without any arguments, in a Terminal and press Enter it outputs the internal help file, as it should.
This works on my system, however it returns the first occurrence of the "VMware Fusion.app" application bundle's path. I have four different visions installed, so this would not be ideal in my situation, although for those that only have one version installed it works.
Solution 2:
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" && 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" && 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.