Open a file with an installed app on macOS
Requires macOS 10.12 or later. macOS 10.13 or earlier needs to download the Swift runtime support libraries.
$ npm install mac-open-with
const openWith = require('mac-open-with');
const apps = openWith.getAppsThatOpenFile.sync('/some/file.mov');
// or
const apps = openWith.getAppsThatOpenType.sync('com.apple.quicktime-movie');
// or
const apps = openWith.getAppsThatOpenExtension.sync('mov');
// [
// { url: 'file:///Applications/iTunes.app/', isDefault: true, icon: '...' },
// { url: 'file:///Applications/Gifski.app/', isDefault: false, icon: '...' },
// { url: 'file:///Applications/Kap.app/', isDefault: false, icon: '...' },
// { url: 'file:///Applications/QuickTime%20Player.app/', isDefault: false, icon: '...' }
// ]
openWith.open('/some/file.mov', apps[0]);
// true
Get a list of app URLs that can open the file type of the given file.
Synchronous version of the method above.
Get a list of app URLs that can open the given file type.
fileType
has to be a Uniform Type Identifier
Synchronous version of the method above.
Get a list of app URLs that can open the given file extension.
Synchronous version of the method above.
Open the given file with the given app URL. appUrl
needs to be one of the URLs returned from getAppsThatOpenFile
or getAppsThatOpenType
.
Returns true
if the file was successfully opened, false
otherwise.
Object type returned by the following three methods.
The URL of the app.
Whether this app is the default app for that file/content type/extension.
The icon of the app in a base64
encoded Data URL.