How to launch OS X apps via the Terminal

NewTerminalIconXThe Terminal is generally reserved as an environment for advanced configuration of your Mac, but there are those who resort to it on a regular basis and use it in conjunction with OS X’s graphical interface to make optimal use of the system. If you do so, then you might find yourself periodically wanting to launch an application, either directly from the command line, or from an automated action like a script. In addition, you can use this feature to launch multiple instances of a standard OS X program, or run it as a different user, such as root, which can give you access to the system in ways you might otherwise not have.

The classic way

As with general Terminal syntax, you can launch an executable script or binary file from the Terminal by simply entering its full path. However, to do so for an OS X app with a graphical interface, you will need to specify the app’s executable file within the application package. In most cases, this will be a subdirectory called /Contents/MacOS/ that contains an executable with the same name as the app. For instance, opening TextEdit in the Applications folder will require you run the following command:


This can be useful for troubleshooting problems with the program, since you will see console output (errors, warnings, and sometimes other activity) output directly to the Terminal window hosting the program, as opposed to having to use the Console utility.

If you would like to run the app as a different user (e.g., the root account), then you can first switch user accounts in the Terminal with the “su” command, or use “sudo” before specifying the path to the Mac OS application, and this will launch the program as root (note that this might not always work):

sudo /Applications/

Keep in mind that launching a program in this way will launch a new instance of it, so if you have TextEdit already open, then you will see another TextEdit program open next to it. This has its benefits in some circumstances, but can interfere with services like Apple’s Resume feature (ie, it may overwrite your current window configuration so when TextEdit is quit, current window positions will not be saved and then restored when the program is next opened).

In addition, keep in mind that when opened in this manner, the Terminal window will be hosting the program, so it must remain open while the program is running—if you close the Terminal window, you will force-quit the program you have opened.

Using the “open” command

One of OS X’s unique Terminal commands is the “open” command that allows you to handle files, programs, and URLs in sometimes unique ways. The benefit of this program is, similar to using the Terminal for directly launching an app in the “classic” way; however, it does have two benefits. First, it is easier to use, and second, it does not require the Terminal remain open:

open -a appname

In this command, replace “appname” with the name of your desired app, and it should launch. Note that by default this command will, similar to the OS X graphical environment, only open one instance of an app, so if the program is already open then this command will switch to it. However, you can use this command to open another instance of the program, by adding the “-n” flag:

open -n -a appname

Keep in mind that as with the classic approach, multiple instances of an application running at the same time under the same user account may have odd consequences with supporting services that the application uses; however, for simple programs and utilities it can be useful to run another instance as root, in order to overcome permissions limitations with your current user account. Also consider apps like the Calculator, where it might be useful to have more than one calculation going at a time.

Terminal open command

With the command run multiple times, you will open multiple instances of the program.

2 thoughts on “How to launch OS X apps via the Terminal

  1. Scott Bayes

    Note that you can also “launch a document” with open:

    open somefile.txt

    will, if necessary, launch the default app for .txt files (or the app specific to somefile.txt file if you changed its association) and open somefile.txt in it. Same for .rtf, .webarchive, .numbers, etc.

    Want to open a Finder window on the directory (folder) you’re currently in (your current working directory) in Terminal?

    open .

  2. Eduardo

    Hi Topher, great write-up!

    Question, I’m not sure why but I’m no longer able to open TextEdit the classic way using sudo in Yosemite.

    When I run the “sudo /Applications/” command I get prompted for the admin password but then nothing happens, although it does seem like TextEdit tries to run but it never shows up, then you get back to the prompt in Terminal.

    I wonder if this is because of an update? I’m using OS X 10.10.4.


Comments are closed.