Skip to content

Commit

Permalink
Add newInstance option for macOS (#253)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
Kudo and sindresorhus committed May 24, 2021
1 parent 0347d3b commit 5e663d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ declare namespace open {
*/
readonly background?: boolean;

/**
__macOS only__
Open a new instance of the app even it's already running.
A new instance is always opened on other platforms.
@default false
*/
readonly newInstance?: boolean;

/**
Specify the `name` of the app to open the `target` with and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const open = async (target, options) => {
options = {
wait: false,
background: false,
newInstance: false,
allowNonzeroExitCode: false,
...options
};
Expand Down Expand Up @@ -115,6 +116,10 @@ const open = async (target, options) => {
cliArguments.push('--background');
}

if (options.newInstance) {
cliArguments.push('--new');
}

if (app) {
cliArguments.push('-a', app);
}
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ Default: `false`

Do not bring the app to the foreground.

##### newInstance <sup>(macOS only)</sup>

Type: `boolean`\
Default: `false`

Open a new instance of the app even it's already running.

A new instance is always opened on other platforms.

##### app

Type: `{name: string | string[], arguments?: string[]} | Array<{name: string | string[], arguments: string[]}>`
Expand Down

0 comments on commit 5e663d6

Please sign in to comment.