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?
open test.cWant to open your test.c file with TextEdit and not with Xcode?
open -a TextEdit test.cor
open -e test.cOpening directories
Want to open Finder at a particular directory, say the user's Documents directory?
open ~/DocumentsOpening URLS
Open our favourite website:
open https://wiki.freepascal.orgSafari not your favourite? Use FireFox maybe:
open -a FireFox https://wiki.freepascal.orgOpening applications
Want to open another copy of a running application? Normally macOS would simply bring the already-running application to the foreground, but:
open -n -a TextEditWant the open command to wait until the application opened has exited?
open -W -n -a TextEditOpening Preference Panes
Want to open the Security Preferences Pane?
open "x-apple.systempreferences:com.apple.preference.security"How about the Firewall tab of the Security Preferences pane?
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:
man openSee 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.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
