open
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
- man 1 'open' [EN]
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.
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'
for profile in 'alex' 'marty'; do
open -a 'Firefox' -n --args -private -P "${profile}"
done
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
- ↑ Apple employees. "OPEN(1)." Apple. https://www.raysoft.ch/data/man/open.1.macos.txt (accessed 19.08.2025)