0

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?

4

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

  • Got it now. The -a is for specifying t. app to open the file with. If I do something like "open index.html" then it opens the file with Safari. Because Safari is the default software for handling html-files on the system. But if I do "open -a Firefox.app index.html" then it opens the html-file with Firefox. Guess it looks into a few locations (Applications-folder, /usr/bin) in case of using the -a flag for to find the afterward following app-parameter. When doing "open Terminal.app" it considers Terminal.app a file to open with no precise software declaration (so it would use the default app). – mizech Feb 5 '17 at 6:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .