Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ function open(target, appName, callback) {
appName = null;
}

var openInDesktop =
appName &&
(appName.toLowerCase() === 'finder' ||
appName.toLowerCase() === 'explorer' ||
appName.toLowerCase() === 'desktop');

switch (process.platform) {
case 'darwin':
if (appName) {
opener = 'open -a "' + escape(appName) + '"';
if (openInDesktop) {
opener = 'open -R ';
} else {
opener = 'open -a "' + escape(appName) + '"';
}
} else {
opener = 'open';
}
Expand All @@ -37,7 +47,12 @@ function open(target, appName, callback) {
// if the first parameter to start is quoted, it uses that as the title
// so we pass a blank title so we can quote the file we are opening
if (appName) {
opener = 'start "" "' + escape(appName) + '"';
if (openInDesktop) {
opener = 'Explorer /select,';
return exec(opener + '"' + escape(target) + '"', callback);
} else {
opener = 'start "" "' + escape(appName) + '"';
}
} else {
opener = 'start ""';
}
Expand Down
4 changes: 4 additions & 0 deletions test/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ describe('open', function () {
it('should open files in the specified application', function (done) {
open(pathTo('with space.html'), 'firefox', done);
});

it('should open a window on the desktop and select the specified file', function(done) {
open(pathTo('asset.txt'), 'desktop', done);
});
});