macOS – In an Electron app, can you combine `Command` with `MediaNextTrack` as a global shortcut?

Viewed 56

I'm trying to add a Cmd+MediaNextTrack shortcut to this app I'm building.

Combined shortcuts (like e.g. Cmd+Shift+Space) seem to work fine in my Electron app.

I am aware of the Security & Privacy / Accessibility setting that needs to be enabled for MediaNextTrack to be accessible. It's enabled locally; the following code works:

    let successfullyRegistered = globalShortcut.register('MediaNextTrack', async () => {
        console.log("==> activated.")
    });

and it actually takes over any "next track" action from Spotify and correctly logs to console.

Also the successfullyRegistered boolean returns as true.

However if I change that code to:

    let successfullyRegistered = globalShortcut.register('Cmd+MediaNextTrack', async () => {
        console.log("==> activated.")
    });

The console is no longer activated.

But successfullyRegistered is true.

And globalShortcut.isRegistered("Cmd+MediaNextTrack") returns true as well.

Various variations of Cmd don't work either: Command+MediaNextTrack, CommandOrControl+MediaNextTrack don't work either.


Question

Is there another way to activate that command + next track shortcut in the app?

1 Answers

After testing, CommandOrControl+MediaNextTrack works on Linux and Windows.

Related