open · macOS command

Also known as: open command

On this page 7

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.

ArgumentExampleResult
Document fileopen notes.txtOpens in the default app for that type
Folderopen ~/DownloadsShows the folder in a Finder window
Current directoryopen .Opens the working directory in Finder
URLopen followed by a web addressOpens in the default web browser
Application bundleopen /Applications/Calculator.appLaunches or activates the app
How open treats different arguments

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.

OptionPurposeTypical use
-a applicationOpen with a named appopen -a Preview image.png
-b bundle identifierSelect the app by bundle IDStable scripts independent of app location
-e and -tUse TextEdit or the default text editorQuick editing of plain text files
-RReveal the item in FinderShow where a downloaded file is stored
-nStart a new instance of the appRun two copies with different settings
-gKeep the app in the backgroundOpen without stealing keyboard focus
-WWait until the app quitsPause a script until editing is done
–argsPass remaining arguments to the appLaunch an app with command-line flags
Frequently used options

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.

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.

ToolPlatformMain difference
openmacOSUses Launch Services and default app settings
xdg-openLinux desktopsUses freedesktop MIME associations
startWindows Command PromptUses Windows file associations
osascriptmacOSRuns AppleScript for deeper app control
Direct binary callmacOSRuns the executable inside the bundle without Launch Services
Open and comparable tools

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.

SymptomCauseFix
Script continues too earlyopen returns immediatelyAdd -W to wait for the app
Wrong app opensDefault handler differs from expectationSpecify the app with -a or -b
Nothing happens over SSHNo graphical user session availableRun it in a logged-in desktop session
Arguments ignoredFlags not placed after –argsPut app flags after –args
App blocked at launchGatekeeper or quarantine attributeVerify the app source before allowing it
Symptoms, causes and fixes

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.