How to run applications via terminal in Mac OS

Author: Sara Rhodes
Date Of Creation: 14 February 2021
Update Date: 1 July 2024
Anonim
Absolute BEGINNER Guide to the Mac OS Terminal
Video: Absolute BEGINNER Guide to the Mac OS Terminal

Content

A terminal is a UNIX command line within an OS X environment. In a terminal, you can enter a command that will run any program or open a file in a specified program. The command can be entered in different ways (depending on your needs), and the program can be launched directly in the terminal window.

Steps

Part 1 of 2: How to start the program

  1. 1 Open a terminal. To do this, click Programs> Utilities> Terminal. You can also open the terminal using Spotlight (in the upper right corner).
  2. 2 Run the program. To do this, in the current directory, enter the "open" command and the full path to the file. If you add the "-a" switch and then enter the program name, the terminal will launch the program no matter where it is stored. For example:
    • To open iTunes, enter:
      open -a iTunes.
    • Use quotes if there are spaces in the program name:
      open -a "App Store"
  3. 3 Open the file in a specific program. Using the "open" command, you can assign a program that will open a specific file type by default. Just enter the path to the file and then enter "-a" followed by the name of the program. If you are unsure how to enter file paths, go to the Troubleshooting section.
    • For example, to open a DOC file in TextEdit, enter:
      open Downloads / Instructions.doc -a TextEdit
  4. 4 Enter additional keys. Enter "info open" to see a complete list of the keys for the "open" command. (When you're done press ControlCto get back to the command line.) Here are some basic keys:
    • Enter "-e" to point to TextEdit, or enter "-t" to point to the main text editor:
      open Downloads / Instructions.doc -e
    • Enter "-g" to run the program in the background, leaving you in a terminal window:
      open -g -a iTunes
  5. 5 Enter "-f" to restart the program. This will delete unsaved changes, but it can help if the program is frozen or malfunctioning:
    • open -F -a TextEdit
  6. 6 Open several windows of one program using the "-n" switch. This is useful if you are comparing different access levels or when you can only open one program window. For example, enter the following command to open multiple windows of the Wake Up Time program:
    • open -n -a "Wake Up Time" (Note: this program is not included with OS X.)
    • This can lead to unexpected behavior of other programs that interact with a program that is running in multiple windows.
  7. 7 Run the program inside the terminal. Instead of just opening a program window, launch it directly from a terminal window. This is useful for debugging as messages and other console notifications are displayed in the terminal window. Here's how to do it:
    • find the program in Finder;
    • right-click on the program and select "Show Package Contents" from the menu;
    • find the executable file. Click Content> MacOS, and then click on the file that has the same name as the program;
    • drag this file to the terminal window. Press Enter to run the program;
    • do not close the terminal window when using the program. Close the program to return to the terminal.

Part 2 of 2: Troubleshooting

  1. 1 Enter the name of the program. If the terminal displays the error "Unable to find application named", find out the exact name of the application by looking at the alphabetical list:
    • click on the apple-shaped icon in the upper left corner of the screen;
    • hold ⌥ Option and click System Information in the menu;
    • in the left pane of the System Information window, click Software> Programs. It will take a couple of minutes to load the list.
  2. 2 Understand what an absolute file path is. If the terminal displays the message “the file ... does not exist”, you entered the wrong file path. To avoid errors, drag the file from the Finder directly into the terminal window (after typing "open" but before pressing Enter). The terminal will display the absolute path to the file, which will always point to this file.
    • An absolute file path always starts with a "/" character. It describes the path to the file relative to the root directory (usually "Macintosh HD").
  3. 3 Understand what a relative file path is. At the beginning of each line, the terminal displays the current directory (the directory you are in). By default, this is your home directory, which is named after your username. A relative file path begins with "./" characters or no characters at all and describes the location of the file in relation to the current directory. If you don't know the relative path to the file, follow these steps:
    • enter pwd to check the current directory. The file you are trying to open must be in this directory, not in a higher-level directory;
    • find the current directory in Finder. Open several folders to find the file you want;
    • enter the names of the open folders in the order in which you opened them. Enter "/" between the folder names. After the name of the last folder, enter “/” and the name of the desired file. For example, open Documents / Writing / Novel / ch3.pdf. (If you want, put “./” in front of the “Documents” folder.)
  4. 4 Change to a different directory. To return to your home directory, enter cd ~ /; to go to a sub-directory, enter “cd” followed by a folder name, for example cd Documents / Finances. Remember that the file you are trying to open must be in the current directory, but that file can be opened in any program regardless of its location.
  5. 5 Enter the correct file name. The file name must include the file extension. If the extension is hidden, use any of the following methods to find it:
    • select the file in Finder. Click on ⌘ Command + I... In the "Information" window, find the line "file name and extension" to find out the full name of the file;
    • or change to the directory with the file. Enter ls in a terminal window to view all files in the directory;
    • or drag the file to the terminal window.

Tips

  • The " *" character can be used as a wildcard to represent any sequence of characters, and the "?" used to represent any single character. These characters can be used in file names, but not in program names. For example, the command open budget * will open the first file (in the directory) whose name begins with the word “budget”. The open budget? .Pdf command will open the "budget1.pdf" file, but not the "budget2015.pdf" file, since the "?" represents only one character.

Warnings

  • Some commands are not available in earlier versions of OS X.