Jump to content

open

From RaySoft

The open 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 files.[1]

Documentation

Syntax

open [PARAMETER ...] [FILE|DIR|URL ...] [--args PARAMETER ...]

Parameters

-a <APPLICATION>
Specifies the APPLICATION to use for opening the file.
--args <ARGUMENTS>
All remaining ARGUMENTS are passed to the opened application in the argv parameter to main().
NOTE:
These arguments are not opened or interpreted by the open tool.
-g
Do not bring the application to the foreground.
-j
Launches the app hidden.
-n
Open a new instance of the application(s) even if one is already running.
-R
Reveals the file(s) in the Finder instead of opening them.
-W
Causes open to wait until the applications it opens (or that were already open) have exited.

Examples

Start applications in macOS if they exist and are not already started
vi "${HOME}/dev/lib/os.sh"
os::start_apps() {
  for app in "${@}"; do
    if ! open -a "${app}.app" -R >'/dev/null' 2>&1; then
      nf::carp "Error finding application: ${app}!"

      continue
    fi

    app="/Applications/${app}.app"

    if ! pgrep -f -q "${app}"; then
      open -a "${app}"
    fi
  done
}
os::start_apps 'Bitwarden'
Start multiple Firefox instances with different profiles using open on macOS
for profile in 'alex' 'marty'; do
  open -a 'Firefox' -n --args -private -P "${profile}"
done
Start multiple Chrome instances with different profiles using open on macOS
app_config_dir="${HOME}/Library/Application Support/Google/Chrome"

for profile in 'alex' 'marty'; do
  open -a 'Google Chrome' -n --args --incognito \
    --profile-directory="${app_config_dir}/${profile}"
done

References

  1. Apple employees. "OPEN(1)." Apple. https://www.raysoft.ch/data/man/open.1.macos.txt (accessed 19.08.2025)