Skip to content

Instantly share code, notes, and snippets.

@juliangruber
Last active August 23, 2020 18:48
Show Gist options
  • Save juliangruber/27ea9c03aa929610f871376b3c30c39c to your computer and use it in GitHub Desktop.
Save juliangruber/27ea9c03aa929610f871376b3c30c39c to your computer and use it in GitHub Desktop.
Here is how to accept files dropped on an @electronjs app's icon in osx. For this to work you need to properly package the app into a `.app`, and to place the CFBundleDocumentTypes spec into it's Info.plist. Here we're using electron-packager.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>All Files</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
<string>public.content</string>
</array>
</dict>
</array>
</dict>
</plist>
// ...
app.on('will-finish-launching', () => {
app.on('open-file', (ev, path) => {
ev.preventDefault();
// send the path to the renderer process via rpc
});
});
// ...
{
"scripts": {
"package": "electron-packager . --all --extend-info extend.plist"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment