open is a macOS command that opens files, folders, URLs and applications from the command line exactly as if the user had double-clicked them in Finder. It hands each argument to Launch Services, the macOS framework that decides which application handles a given document type or URL scheme, so open report.pdf launches the default PDF viewer and open . shows the current directory in a Finder window.
In Terminal & scripting work on macOS, the open command is the standard bridge between the shell and the graphical desktop. It lets scripts, Homebrew formulas and developers launch apps, reveal files and open web pages without hard-coding application paths, and its options control which app is used, whether a new instance starts and whether the script waits for the app to quit.
How the open command works with Launch Services
The open command works by delegating every argument to Launch Services rather than executing anything itself. Launch Services looks at the Uniform Type Identifier of a file or the scheme of a URL, consults the registered handlers, and starts or activates the appropriate application with the item as a document to open.
Because of this design, the command respects the same default app choices that the user sets through Get Info or the Open With menu. It also returns quickly by default: the shell prompt comes back as soon as the request is delivered, not when the application finishes.
The table below shows how different argument types are handled.
| Argument | Example | Result |
|---|---|---|
| Document file | open notes.txt | Opens in the default app for that type |
| Folder | open ~/Downloads | Shows the folder in a Finder window |
| Current directory | open . | Opens the working directory in Finder |
| URL | open followed by a web address | Opens in the default web browser |
| Application bundle | open /Applications/Calculator.app | Launches or activates the app |
When a path does not exist, open prints an error and exits with a nonzero status, which allows scripts to detect failure with ordinary shell tests.
Key options of the open command
The options of open control which application is chosen, how it starts and how the command interacts with the script. The most useful ones appear in the following table; the full list is available in the manual page through man open.
| Option | Purpose | Typical use |
|---|---|---|
| -a application | Open with a named app | open -a Preview image.png |
| -b bundle identifier | Select the app by bundle ID | Stable scripts independent of app location |
| -e and -t | Use TextEdit or the default text editor | Quick editing of plain text files |
| -R | Reveal the item in Finder | Show where a downloaded file is stored |
| -n | Start a new instance of the app | Run two copies with different settings |
| -g | Keep the app in the background | Open without stealing keyboard focus |
| -W | Wait until the app quits | Pause a script until editing is done |
| –args | Pass remaining arguments to the app | Launch an app with command-line flags |
Selecting an application with -b and a bundle identifier such as com.apple.TextEdit is more robust than -a with a display name, because the bundle ID does not change when an app is renamed, localized or moved.
The -f option reads standard input and opens the text in the default text editor, so a pipeline such as ls -l | open -f produces an editable document. Combined with -W, open can act as a simple graphical editor for tools that call an external editor.
How open compares with related commands
The open command is specific to macOS, and other systems and other macOS tools cover overlapping tasks with different behavior. Knowing the differences prevents scripts from breaking when they are moved between platforms.
| Tool | Platform | Main difference |
|---|---|---|
| open | macOS | Uses Launch Services and default app settings |
| xdg-open | Linux desktops | Uses freedesktop MIME associations |
| start | Windows Command Prompt | Uses Windows file associations |
| osascript | macOS | Runs AppleScript for deeper app control |
| Direct binary call | macOS | Runs the executable inside the bundle without Launch Services |
Calling the executable inside an application bundle directly, for example under Contents/MacOS, bypasses Launch Services and ties the process to the terminal session. This can be useful for debugging output, but it skips normal app activation and is rarely the right choice in everyday scripts.
Practical uses in scripting and daily work
Developers and administrators use open to connect command-line workflows with graphical apps without leaving the terminal. Typical patterns include:
- open -R on a build artifact to show the newly built file in Finder for drag-and-drop.
- open -a with a code editor to open a whole project folder from the current directory.
- open with a local address on localhost port 3000 after starting a development server.
- open -W -t in a script that needs the user to edit a configuration file before continuing.
- open -n –args to run a second browser instance with a separate profile for testing.
Because open follows default app settings, scripts that rely on a specific application should name it explicitly with -a or -b instead of assuming the default handler.
Limitations and common mistakes
Most problems with the open command come from forgetting that it is asynchronous and that it depends on a logged-in graphical session. The table summarizes frequent issues.
| Symptom | Cause | Fix |
|---|---|---|
| Script continues too early | open returns immediately | Add -W to wait for the app |
| Wrong app opens | Default handler differs from expectation | Specify the app with -a or -b |
| Nothing happens over SSH | No graphical user session available | Run it in a logged-in desktop session |
| Arguments ignored | Flags not placed after –args | Put app flags after –args |
| App blocked at launch | Gatekeeper or quarantine attribute | Verify the app source before allowing it |
Security controls still apply: open does not bypass Gatekeeper checks, code signing requirements or privacy permissions. An application blocked when double-clicked is equally blocked when opened from Terminal.
In everyday language
On a Mac, you normally open things by double-clicking them. The open command does the same double-click, but with typed words in the Terminal window. You type open, then the name of a file, a folder or a web address, and the Mac opens it in the usual app.
It is like asking a helpful receptionist to hand a document to the right colleague. You do not need to know who handles PDFs or web pages; the Mac already knows and picks the right app for you.
Seen in the real world
A web developer works on a site in Terminal. After starting the local development server, the developer types open with the localhost address on port 8080 and the default browser shows the page at once, without any clicking through menus.
When a build script finishes producing a release archive, its last line runs open -R on the archive, so Finder appears with the new file already selected and ready to upload. For a configuration step, another script uses open -W -t settings.ini, which opens the file in the text editor and pauses until the developer closes it.
The result is a workflow in which the terminal and the desktop work together smoothly: routine steps take seconds, and the scripts behave the same on every Mac in the team because they rely on standard macOS behavior.