Bug electron on mac

Steps to reproduce

I’m using this in a script

export async function openDirectoryInFileManager(dirPath: string) {
    let shell = window.electron.remote.shell;
    try {
        await shell.openExternal(dirPath);
    } catch (err) {
        console.log(err);
    }
}

and this is generating an error on MacOS. It’s working under Windows (11)

Uncaught (in promise) Error: Invalid URL
    at /Applications/Obsidian.app/Contents/Resources/app.asar/node_modules/@electron/remote/dist/src/main/server.js:465:71
    at IpcMainImpl.<anonymous> (/Applications/Obsidian.app/Contents/Resources/app.asar/node_modules/@electron/remote/dist/src/main/server.js:323:27)
    at IpcMainImpl.emit (node:events:513:28)
    at WebContents.<anonymous> (node:electron/js2c/browser_init:2:89772)
    at WebContents.emit (node:events:513:28)
eval	@	move-out-menus.ts:22
await in eval (async)		
e.handleEvent	@	app.js:1
click	@	app.js:1
apply	@	/Applications/Obsidi…acks-registry.js:54
(anonymous)	@	/Applications/Obsidi…derer/remote.js:346
(anonymous)	@	/Applications/Obsidi…derer/remote.js:328
emit	@	node:events:513
onMessage	@	node:electron/js2c/renderer_init:2

Did you follow the troubleshooting guide? [Y/N]

Expected result

Actual result

Environment


Additional information

moved to developers and api

I think you want to be using shell.openPath() instead. openExternal is for URLs

1 Like

ok thanks I had an issue on mac with this.
I did this now

export async function openDirectoryInFileManager(dirPath: string) {
    // if(Platform.isMacOS) shell = window.electron.remote.shell;
    let shell = window.electron.remote.shell;
    try {
        // await shell.openExternal(dirPath); // I had a bug on mac
        await shell.openPath(dirPath); // let's try this
    } catch (err) {
        console.log(err);
    }
}