2

My application is an Electron.js app

I type this command in the terminal to open a file with my app:

open "/Users/Bob/Pictures/test.jpg" -a myApp

In my process.argv I get an Apple event, something like '-psn_0_#######', How do I use this event to get the jpg?

Daniel
  • 667
  • 2
  • 11
  • 25

1 Answers1

3

On windows you parse process.argv (in the main process) to get the filepath. but on mac you need to listen to the 'open-file' event. This can be done like this:

app.on('will-finish-launching', () => {
    app.on('open-file', (event, path) => {
        // do something
    });
});

https://github.com/electron/electron/blob/master/docs/api/app.md#event-open-file-macos

Daniel
  • 667
  • 2
  • 11
  • 25