The open command

It’s time for adventures in the open command!

Most admins know the open command. They’ll use it in bash scripts or as part of an item in Self Service to open a file, an application, a URL, or a System Preference Pane (among other things). However there are quite a few additional features beyond the surface level open command that a lot of admins aren’t aware of, so I’d like to share those with you now.

Let’s take a look at a few basic examples of the open command below:


File
open /path/to/file.pdf

Application
open "/Applications/Brave Browser.app"

URL
open https://google.com

System Preference Pane
open "/System/Applications/System Preferences.app"

As Brett Terpresta points on this excellent post, there’s a host of extra options and flags available when using the open command.

Let’s say you want to open a file or a url with a specific app. Maybe you have an internal company url that only works with Chrome and you want to make sure that your script or Self Service item that opens that site always opens in the Chrome browser. Or perhaps you’re deploying a pdf with certain features that only work inside of Adobe Acrobat Reader. You can use the -a flag to specify a specific application by name or -b to specify a specific application by its bundle identifier.

Let’s expand on a few of our original examples:

File
open -a "Adobe Acrobat Reader DC" /path/to/file.pdf
open -b com.adobe.Reader /path/to/file.pdf

URL
open https://google.com
open -a "Brave Browser" https://google.com
open -b com.apple.Safari https://google.com

In the examples above, I can make sure that the PDF I am opening doesn’t default to the macOS Preview.app, but instead Adobe Acrobat Reader. Or in the case of urls, I can’t specifically open the url in Brave Browser or Safari simply by calling on the application name or bundle id.

Unsure how to find an app’s bundle identifier? Open Terminal and type:
codesign -dr - /Applications/appname.app to get it's identifier.

$codesign -dr - /System/Volumes/Data/Applications/Brave\ Browser.app

Executable=/System/Volumes/Data/Applications/Brave Browser.app/Contents/MacOS/Brave Browser
designated => identifier "com.brave.Browser" and anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */

In the example above, I can see that com.brave.Browser is the bundle identifier.

These are some useful tricks that mac admins can leverage to add application specificity to their scripts when opening files or URLS. There’s a few other tricks that Brett covers, so be sure to go check out his post.