When I attempt to open a file with a double click in my Electron app, Argv[1] gives me an unexpected value

When attempting to open a file by double-clicking, I encounter an issue while using electron-packager to build the application for the Mac App Store.

Although I have set up the electron app to launch when a file is double-clicked, it appears that the filename of the opened file is not sent as a command line parameter to the app.

Instead of receiving the requested file path in argv[1], I am getting -psn_0_857362. I had anticipated argv[1] would contain the file path, but this does not seem to be the case.

Below is a simplified version of the code snippet used in main.js:

ipcMain.on(
'getOpenFile',
function( e ) {

    let data = null;

    if ( process.argv.length >= 2 ) {
        data = process.argv[1];
    }

    e.returnValue = data;

}
);

I am puzzled as to why the file path is not being displayed. Is there a limitation imposed by the Mac App Store or is there another step required to enable the expected functionality?

Answer №1

If you are using macOS, it may be necessary to handle the app event known as open-file from the main process like this:

app.on('open-file', (event, path) =>
{
    event.preventDefault();
    console.log(path);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a personalized compilation process that eliminates the two-way binding

In my Angular 1.5.8 application, I have created an attribute directive called my-directive. I am trying to apply this directive to an element while passing two additional parameters - one with one-way binding (@) and the other with two-way binding (=). Ev ...

"Encountered a console.log error in native code while using Google Chrome and Android browsers

Can someone help me troubleshoot an issue I'm having with displaying data after a user clicks on the sign-up button? The function works fine on Mozilla Firefox, but I get a native code error on Google Chrome and Android browsers. Can anyone spot what ...

I'm having trouble getting my HTML POST request form to connect with the Express app.post. Any tips on how to properly pass on numeric variables to a different POST request?

There seems to be a misunderstanding or error on my part regarding POST and GET requests based on what I've read online. On myNumber.ejs, I have a submit form. Upon submission, the view switches to Add.ejs. The goal is for Add.ejs to display both the ...

What is the best approach for incorporating sub-navigation within a page popup in a Next.js project?

In the midst of my Next.js project, there is a requirement to showcase a chat popup consisting of multiple sub-pages like user registration, conversation page, and more. Hence, seamless navigation inside this popup is necessary. The idea is not to alter th ...

The outcome yielded by a repeating function

This recursive function commonHint in the Meteor server is causing result to be undefined in the console, even though finalRes has a value. Any ideas on how to properly return finalRes to the caller? Thanks! // Calling the recursive method let re ...

What is the best way to create space between table rows without using border-spacing?

I've been attempting to use the margin-bottom property on my table in order to separate the rows, but it doesn't seem to have any effect. I then tried using flex, which did work, but the table rows did not inherit the width and I had to specify a ...

When will the javascript file fire if it has this implementation?

Can someone help me make sense of this jquery snippet? (function( window, undefined ) { //All the JQuery code is included here ... })(window); I'm curious, if a .js file is loaded in a page using the <script> tag, at what point does it ...

What's the reason popstate does not trigger in Safari during the loading of an iframe?

When using Safari, I've noticed that if an iframe is loading and the user changes the history state by navigating back or forward, the popstate event doesn't get triggered. This results in the application state being out of sync with the window l ...

Tips on swapping out a part in ExtJS

Currently, my ExtJS window features a toolbar at the top and loads with a plain Panel at the bottom containing plain HTML. Everything is working smoothly in this setup. However, I now wish to replace this bottom panel (referred to as 'content') w ...

Error Alert: Attempting to access the 'prototype' property of an undefined value has resulted in a TypeError after switching to react-scripts version 4.0.3

I encountered a problem where I received the following error message: (Uncaught Error: Module build failed (from ./node_modules/source-map-loader/dist/cjs.js)). After attempting to resolve it by using npm install, a new error popped up in the console: path ...

What is the best way to showcase the output of a Perl script on a webpage

I recently came across a resource discussing the process of executing a perl script from a webpage. What is the best way to run a perl script from a webpage? However, I am facing a situation where the script I have takes more than 30 seconds to run and d ...

Vue router is unable to render or mount the component at the root path

I am currently working on a webpage using vue, vue-router, and laravel. I have encountered an issue where the Home component is not being rendered in the router-view when I access localhost/myproject/public_html/. However, if I click on the router link to ...

The ForEach function does not execute actions on every individual object, but rather only once

I am currently developing a Deck building application for a card game. In addition, I have set up a database to manage the cards that I sell and play with. The deck builder tool I created allows me to deplete the stock of sellable cards when adding them to ...

Is it possible to simultaneously employ two asynchronous functions while handling two separate .json files?

Is it possible to work with 2 .json files simultaneously? My attempt did not succeed, so I am looking for an alternative method. If you have a suggestion or know the correct syntax to make this work, please share. And most importantly, does the second .j ...

How can you transform a nested array into a flat JavaScript map?

If we consider a JavaScript Map structured like this: [ { id: 1, name: "Foo", contents: [1,2,3], morecontents: ["a","b"], }, { id: 2, name: "Bar", c ...

jquery personalized auto-suggest

I have multiple input[type="text"] elements with the class .autocomp. When I search for something, PHP retrieves data from a MySQL database and displays it in HTML format using jQuery. My question is, what is the most effective approach among these option ...

What is the best way to invoke parent component methods from a child component?

I'm struggling with a scenario where I want to call methods— _handleFirstName and _handleLastName— from the parent component <Home/>, in a child component named <NormalTextField/>. The ultimate goal is to allow the user to input text, ...

Rendering a Pop-up for a Single Array Item Retrieved from an API in ReactJS

Apologies if my wording is unclear, this is my first question, and I'm relatively new to JS/React... I have successfully mapped through an array from an API call and displayed the necessary information. How can I display a popup for a single element ...

Modifying the structure of serialized data

After serializing a JS form, the data looks like this: .....&xx=xxx&otherError=&input=SMS&message=sdfgs&...... Can anyone provide guidance on how to replace the value of message with the content of a textarea before making an ajax cal ...

JavaScript Regular Expression for standardizing phone number input

I'm working with an input for a phone number in French format which can accept two different formats: 0699999999 +33699999999 There is currently no check for the length of the number. In the database table, the field is varchar 12, but shorter inp ...