In macOS, one of the options to open an application via "open" command would be like so:
$ open -a "Google Chrome"
$ open -a "GIMP"
But I realized that the command above works even if the apps weren't in /Applications
nor ~/Applications
directory.
So, "how can I get the path of this app" using a command line?
I tried to use the find
command and search the whole machine, but I thought that there would be an easier way to find it.
The reason is that I need to access the bin file inside the ".app" directory like below:
$ /path/to/GIMP.app/Contents/MacOS/GIMP-bin --help-all
Since the command below doesn't seem to parse the arguments.
$ open -a "GIMP" --args --help-all
Show the path to a file or folder On your Mac, click the Finder icon in the Dock to open a Finder window. Choose View > Show Path Bar, or press the Option key to show the path bar momentarily.
PATH is an essential environment variable that decides how programs and commands work on macOS. Setting the PATH variable for a program or script allows you to run it from anywhere on the file system without specifying its absolute path.
If you type cd .. (that's two periods), you'll go to the directory above the one you're currently in. So if you're in your home folder, and type cd .. , you'll go to your Mac's /Users folder. And if you type cd - (hyphen) you'll go back to the directory you were in before the last time you issued the cd command.
I think I found another answer.
This script won't launch the app while checking the paths like the Applescript one.
Since it just grep
s the lsregister
's dump result, it might not be as accurate as the Applescript, but so far it seems to work.
Script:
An alternative way to find the application path with bash
(without using AppleScript) using lsregister
command.
#!/bin/bash
# findApp.sh
# ==========
NAME_APP=$1
PATH_LAUNCHSERVICES="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
${PATH_LAUNCHSERVICES} -dump | grep -o "/.*${NAME_APP}.app" | grep -v -E "Caches|TimeMachine|Temporary|/Volumes/${NAME_APP}" | uniq
Usage:
$ ./findApp.sh "Google Chrome"
/Applications/Google Chrome.app
$ ./findApp.sh GIMP
/Volumes/External_HDD/Applications/GIMP/GIMP_v2.8/GIMP.app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With