Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On macOS, how can I find the app's path which opens with “open” command?

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

  • macOS HighSierra (OSX 10.13.5)
like image 714
KEINOS Avatar asked Jul 12 '18 03:07

KEINOS


People also ask

How do I find the path of an app on a Mac?

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.

What is $PATH in Mac?

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.

How do I navigate to a directory in Terminal Mac?

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.


1 Answers

I think I found another answer.

This script won't launch the app while checking the paths like the Applescript one.

Since it just greps 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
like image 64
KEINOS Avatar answered Sep 25 '22 01:09

KEINOS