Macos – Shell script Mac OS X App : get its path

bundlemacospathshell-script

In Mac OS X, from a shell script application's point of view, how can I get its bundle directory path for use in a shell script? When using the env command, it returns that the app's execution path is /, and no environment variable helps. I'm doing this because I would like to access some resources of the bundle, and because the app is not always installed in /Applications.

Thanks!

Best Answer

DIR=$(cd "$(dirname "$0")"; pwd) will give the shell script's directory name. For a shell script app, this will be /path/to/Your shell script application.app/Contents/MacOS.

Related Question