TechEarl

Open Apps, Files, and URLs From the macOS Command Line with open

The macOS open command launches apps, files, folders, and URLs from the Terminal: open a file in its default app, reveal it in Finder, open a URL in a specific browser, and the zsh quoting gotcha that breaks URLs.

Ishan Karunaratne⏱️ 8 min readUpdated
Share thisCopied
Use the macOS open command to launch apps, open files in a chosen app, reveal files in Finder, and open URLs in a specific browser from the Terminal.

The macOS open command hands a file, folder, or URL to whatever app the system would use if you double-clicked it. The whole point is that it bridges the Terminal and the GUI: you stay in the shell, but the thing you are opening lands in the right Mac app. The shortest useful version:

bash
open report.pdf

That opens report.pdf in your default PDF app (usually Preview), exactly as a double-click in Finder would. No flags, no app name, no path gymnastics. The rest of this page is the variations I actually reach for: a specific app, the current folder, a URL in a chosen browser, and the one zsh gotcha that silently breaks URLs.

Open a file in its default app

Pass open a path and it asks LaunchServices which app owns that file type, then launches it:

bash
open notes.md          # opens in your default Markdown/text app
open photo.heic        # opens in Preview (or whatever you set)
open archive.zip       # hands it to Archive Utility, which unzips it

This is the everyday case. The file extension drives the choice, so the same open data.csv lands in Numbers on one Mac and in Excel on another, depending on what each machine has set as the default for that type.

Open the current folder in Finder

open . opens the current working directory in a Finder window. This is the one I use most:

bash
open .              # current directory in Finder
open ~/Downloads    # any folder
open ..             # parent directory

It is the fastest way to jump from a deep terminal path into a Finder window without re-navigating by hand. A bare open with a directory argument opens that directory; open . is just the special case for "right here."

Open with a specific app: open -a

To force a particular app instead of the default, use -a with the app name. The name is case-insensitive and you do not include .app:

bash
open -a "Visual Studio Code" server.js
open -a Preview diagram.png
open -a "Sublime Text" .

If the app name has a space, quote it. open -a "Google Chrome" works, open -a Google Chrome tries to open an app called Google and then a file called Chrome. When the named app is not installed, open fails with Unable to find application named '...', which is the usual sign of a typo or a wrong name (it is "Visual Studio Code", not "VS Code").

There is also -b, which targets an app by its bundle identifier rather than its display name. That is steadier in scripts because a bundle ID does not change when Apple renames an app:

bash
open -b com.apple.TextEdit notes.txt

Open a file in TextEdit or the default editor

Two shortcuts skip the app-name dance for editing plain text. -e always uses TextEdit; -t uses whatever app is registered as the default editor for that file type:

bash
open -e config.txt    # always TextEdit
open -t config.txt    # default text editor (could be BBEdit, VS Code, etc.)

I reach for -e when I want a quick, no-surprises text window and do not care what my default editor happens to be set to.

Open a URL in the default browser

Give open an http or https URL and it opens in your default browser:

bash
open https://techearl.com

This is handy at the end of a script ("build done, open the local preview") or just to fling a link from the terminal into a browser tab.

Open a URL in a specific (non-default) browser

This is the combination people search for and miss: -a plus a URL opens that URL in the named browser, regardless of which browser is your system default.

bash
open -a "Safari" https://techearl.com
open -a "Firefox" https://techearl.com
open -a "Google Chrome" https://techearl.com

So if Safari is your default but you want to check a page in Firefox, open -a Firefox <url> does it without changing any settings. To pass command-line flags through to the browser itself, use --args (everything after it goes to the app, not to open). For example, telling Chrome to make itself the default browser:

bash
open -a "Google Chrome" --args --make-default-browser

There is no general "set default browser from the command line" command on macOS; that Chrome-specific flag is the closest thing, and it only works because Chrome itself understands --make-default-browser. On recent macOS it does not flip the default silently either: it triggers the system "Use Chrome as your default browser?" confirmation dialog, which you still have to approve by hand.

The zsh quoting gotcha (quote your URLs)

This one bites people on every modern Mac. Since Catalina, the default shell is zsh, and zsh treats ?, &, and # as special characters. An unquoted URL with a query string gets mangled before open ever sees it:

bash
open https://example.com/search?q=mac&page=2     # zsh breaks this
open 'https://example.com/search?q=mac&page=2'   # quote it, works

Without quotes, zsh tries to glob the ? and treats & as "run in background," so you get a no matches found error or a half-eaten URL. Always single-quote a URL that contains ?, &, or #. It is a good habit even in bash; in zsh it is mandatory.

Reveal a file in Finder instead of opening it

-R selects and highlights a file in a Finder window rather than opening it. Useful when you want to see a file in context, not launch it:

bash
open -R ~/Projects/site/dist/index.html

The Finder window opens at the enclosing folder with the file selected, ready to drag, rename, or look at alongside its neighbors.

Other flags worth knowing

A few more from the open(1) man page that earn their keep:

bash
open -n -a Safari            # force a NEW instance even if Safari is running
open -g -a Music song.m4a    # open in the background, do not steal focus
open -W -a Preview scan.pdf  # wait until that app quits before the shell continues

-n matters when you genuinely want a second copy of an app running. -g is nice in scripts that should not yank you out of the terminal. -W (wait) lets you script "open this, and do the next step only after I close it." You can also pass several files at once: open *.png opens every PNG in the folder in the default image app.

Linux and Windows equivalents

open is macOS only. On Linux the equivalent is xdg-open file-or-url (from xdg-utils), which hands the target to your desktop environment's default handler. On Windows the rough equivalent is start file-or-url in cmd (note start opens a URL or document with the registered handler). If you write cross-platform scripts, those are the two names to branch on.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

Tagsopen commandmacOSTerminalCLIFinderopen url terminalopen app from terminal

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts