MacOS – Terminal: open-command -a flag – Why isn’t it necessary for some software

macosterminal

When I use this command to open some text-file …

> open myFile.text

… then it works perfectly fine. TextEdit opens up and I can read / edit the file.
Works with pdf-files the same way too.

But when I do this …

> open Terminal.app

… then I get an error message:

The file /Users/michael/Downloads/Terminal.app does not exist.

I've found out that I have to add an -a flag:

> open -a Terminal.app

Then the command works as expected: A second terminal is opened.

The man-page of the open-command says:

*-a application

Specifies the application to use for opening the file*

Okay, well … but …

Why do some software work WITHOUT using the -a flag? While other software demands it to be there?

Best Answer

You are doing two different things here.

The text one is open a file with the application that open associates with the file extension.

The Terminal one is you trying to open a named application.

What open does is first look, using the full path name, for the file that is named, as you only give a file name it is a relative path it looks for that file in the current directory. (Thus for Terminal.,app it says it can't find the file and then gives up). When it has found the file it then searches for the default application for the file's extension, then sees if the application is running, if not it starts the application. Finally open sends a message to the application to deal with the file.

Passing -a to open tells open to use the named application, it searches its database for previously opened apps and so does not need the full path to find Terminal.app