MacOS – Viewing/Changing App paths used by `open -a foo.app …`

applicationscommand linelaunch-servicesmacos

When using open -a iTerm.app SOMEPATH from a shell-script or Emacs eshell command, it appears to launch a different instance of iTerm than the one in /Applications/iTerm.app that I'd expect.

Explicitly specifying the app path like:

open -a /Applications/iTerm.app SOMEPATH works as expected.

This leads me to suspect that there's a lookup table/database somewhere (probably part of LaunchServices) that's mapping bare .app names to an on-disk path, and it's somehow confused as to which it should be using (I do have multiple instance of iTerm on disk, from when I've been playing around with compiling from source. None are in my $PATH, however.)

Any suggestions on how to find what on-disk path an
open -a <non-absolute .app name> will use, and ideally, how it can be changed?

Best Answer

If you type the following commando:

open -R iTerm.app

it will reveal the iTerm.app you're currently selecting in Finder.

If you type

open -a /applications/iTerm.app

it will open the iTerm.app in the /Applications folder as you said.

If you type

open -a iTerm.app

it will open iTerm.app in the current location. (you can type ls to see the contents of the current folder, or use the above method (-R)

As a general hint, please type

open --help

to see the methods/commands available you can use.