Sign in Join
Wiki copytemporary

macOS Open Sesame

(macOS only)

Overview

The macOS /usr/bin/open command line utility is a veritable Aladdin's cave of utility. The command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified file. If the file is in the form of a URL, the file will be opened as a URL. See Executing External Programs to run the command from within your application.

Opening files

Want to open a test.c file?

bash
  open test.c

Want to open your test.c file with TextEdit and not with Xcode?

bash
  open -a TextEdit test.c

or

bash
  open -e test.c

Opening directories

Want to open Finder at a particular directory, say the user's Documents directory?

bash
  open ~/Documents

Opening URLS

Open our favourite website:

bash
  open https://wiki.freepascal.org

Safari not your favourite? Use FireFox maybe:

bash
  open -a FireFox  https://wiki.freepascal.org

Opening applications

Want to open another copy of a running application? Normally macOS would simply bring the already-running application to the foreground, but:

bash
  open -n -a TextEdit

Want the open command to wait until the application opened has exited?

bash
  open -W -n -a TextEdit

Opening Preference Panes

Want to open the Security Preferences Pane?

bash
  open "x-apple.systempreferences:com.apple.preference.security"

How about the Firewall tab of the Security Preferences pane?

bash
  open "x-apple.systempreferences:com.apple.preference.security?Firewall"

Note that this scheme was new in Yosemite (macOS 10.10) and that Apple subsequently restricted use of the URL scheme in El Capitan (macOS 10.11).

More options

For the full gamut of open command options, open a Terminal and call up the Unix man page:

bash
 man open

See also (cross-platform)


From the Free Pascal wiki, page "macOS Open Sesame", as it stood on 2023-03-31 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.