The "Terminal" window of Apple's OS X operating system allows the user to execute UNIX commands directly. Using this tool and the "open" command you can open any application or file (via your chosen program) directly from the command line. There are several parameters to adapt this command to your needs, including the ability to run the required application directly within the "Terminal" window.
Steps
Part 1 of 2: Run an Application
Step 1. Launch the "Terminal" window
Look for the Terminal application icon inside the Utilities folder which is contained in the Applications directory. Alternatively, you can access this tool by searching through the "Spotlight" field, located in the upper right corner of the desktop.
Step 2. Launch an application from anywhere
Normally, the command open it prompts you to indicate the complete installation path of the application to run; however, using the parameter - to followed by the name of the program, the "Terminal" window will be able to open it regardless of where it is stored. Eg:
-
To start iTunes, use the command:
open -a iTunes
-
If the application name has a space in it, enclose it in quotation marks:
open -a "App Store"
Step 3. Open a file using a specific application
You can use the "open" command to replace the default application used for opening a specific file type with the one you want. To do this, simply type the full path to the file, followed by the "-a" parameter and the name of the application to use. If you are unsure how to enter the full file name, please refer to the "Troubleshooting" section later in this article.
-
For example, if you want to open a file with the ".doc" extension using the "TextEdit" program, type the command:
open Download / Instruzioni.doc -a TextEdit
Step 4. Use additional parameters
To obtain the complete list of parameters related to the command open, use the command info open (When finished, press the key combination Ctrl + C to return to the command line prompt. Here is a short list of the basic parameters:
-
Use the parameter - And to use the text editor "TextEdit" or - t to use the system default:
open Downloads / Instructions.doc -e.
-
Add the parameter - g to run the specified application in the background. This way you can continue to use the Terminal window to perform other operations:
open -g -a iTunes.
Step 5. Add the -F parameter to start a new instance of the specified application
This operation deletes all changes and data that have not been saved, but it can be useful in the event that a specific document causes the application to hang while loading:
open -F -a TextEdit
Step 6. Start multiple instances of the same application using the -n parameter
This feature can be useful if you need to compare different access levels or if the application's graphical interface allows you to use a single window. For example, type this command several times to start multiple instances of the "Wake Up Time" application:
- open -n -a "Wake Up Time" (note: this application is not a default program of the OS X operating system).
- However, remember that this function could generate unexpected behavior of other applications that interact with the various instances of the one you are interested in.
Step 7. Run an application inside the "Terminal" window
Instead of starting a program normally, do it within the "Terminal" window. This step is very useful when debugging, as error messages and console outputs will be displayed within the "Terminal" window. Here is the sequence of steps to use:
- Within the "Finder" window, locate the application you are interested in.
- Select its icon with the right mouse button, then choose the "Show original" option.
- Find the name of the executable file. Normally, it is stored inside the MacOS folder, located in the Contents directory, and is characterized by the same name as the application it refers to.
- Drag the executable file into the empty "Terminal" window. When finished, press the Enter key to start the program.
- While using the application, do not close the "Terminal" window. To return to using the command line, close the application as you normally would.
Part 2 of 2: Troubleshooting
Step 1. Find the name of the application
If the error message "Cannot find the application called…" appears in the "Terminal" window, it means that the program name is incorrect. You will need to identify the correct name by consulting the list of installed applications sorted alphabetically:
- Select the Apple logo, located in the upper left corner of the screen.
- Press and hold the ⌥ Option key, then choose the System information item from the drop-down menu that appears.
- Choose the Software and Applications items in succession, placed in the side menu of the window that appeared. Loading the list of installed applications may take several minutes.
Step 2. Understand the meaning of the absolute path of a file
If the error message "The file [filename] does not exist" appears in the "Terminal" window, it means that you have not typed the correct path to access the item indicated. A simple way to avoid making mistakes is to drag the file of your interest from the "Finder" window directly into the "Terminal" window (after typing the "open" command, but before pressing the "Enter" key). This way, the full path to the file will be automatically entered into the command line.
The full path of a file always begins with the symbol /. The latter describes the path to the file starting from the computer's root folder, which is normally "Macintosh HD".
Step 3. Understand the relative path meaning of a file
The "Terminal" window prompt always shows the current directory it refers to. By default, this is the "home" folder, named after the user it belongs to. A relative file path always begins with symbols ./ or without any special characters and describes the location of a file in relation to the currently selected folder. If you have trouble locating this information, please follow these instructions:
- Type the pwd command to check the current directory. The file you are trying to open must necessarily reside in the current folder and not in one of the higher levels.
- Locate the current directory within "Finder". Navigate to the set of folders needed to navigate to the file whose content you want to view.
- In the "Terminal" window, type the name of all the folders you have opened via "Finder", being careful to respect their order. Separate each name with a "/" symbol, then end the path by entering the file name. Here is an example command open Documents / Writing / Novel / ch3.pdf (if you want you can insert the symbols "./" before the "Documents" folder: the final result does not change).
Step 4. Change directory
To return directly to your "Home" folder, type the command cd ~ /. Alternatively, you can access a subfolder with the "cd" command followed by the directory name. Here is an example cd Documents / Finances command. Remember that the file you want to open must necessarily reside in the folder you are currently in. You can also use any application to open the file, regardless of its location.
Step 5. Find the correct file name
When typing the file name, you need to remember to include the extension as well. If this information is hidden, use one of the following methods to find it:
- Select the file in the "Finder" window. Press the key combination ⌘ Command + I to open the "Info" window. Within the latter, locate the "Name and extension" section to find the complete file name.
- Alternatively, change the directory to the folder that contains the file name. Type the ls command in the "Terminal" window to view the list of all the files contained in the current directory.
- Drag the file directly into the "Terminal" window.
Advice
-
Within commands, you can use the metacharacter * to represent any sequence of characters. The metacharacter ?
instead it is used to represent any single character. These special symbols can be used with filenames, but not application names. For example, the open budget * command displays the contents of the first file in the current folder whose name begins with "budget". The open budget?. Pdf command would be able to display the contents of the "budget1.pdf" file, but not that of the "budget2015.pdf" element because the "?" represents a single character and not an entire string.