macOS Open Sesame
The macOS /usr/bin/open command 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.
Want to open a test.c file?
Want to open your test.c file with TextEdit and not with Xcode?
open -a TextEdit test.c
open -e test.c
Want to open Finder at a particular directory, say the user's Documents directory?
Open our favourite website:
Safari not your favourite? Use FireFox maybe:
open -a FireFox https://wiki.freepascal.org
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 TextEdit
Want the open command to wait until the application opened has exited?
open -W -n -a TextEdit
Opening Preference Panes
Want to open the Security Preferences Pane?
How about the Firewall tab of the Security Preferences pane?
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).
For the full gamut of open command options, open a Terminal and call up the Unix man page: