I am trying to run MacOS shortcuts via NodeJS script. To achieve that I created shortcuts in the MacOS Shortcuts app, which normally run in the terminal (ZSH) by typing shortcuts run shortcutname
(Docs). They work fine when typing them directly into the terminal, but not when called from a NodeJS script.
My script looks like this:
exec('shortcuts run shortcutname', (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
When starting the script from the terminal node script.js
it does nothing. It does not return anything nor does it finish. I tried replacing the command shortcuts run shortcutname
by other commands the system should know. For example ls
, or git
. They all work. Also when I leave out the shortcutname
in the end, it complains about the missing parameter.
I was suspecting missing access rights, but apparently NodeJS runs as my normal user. Running whoami
in script context returns my user name.
NODE_DEBUG=cluster,net,http,fs,tls,module,timers node script.js
did not show anything unusual. I also tried using the full path of the binary. which shortcuts
gave me /usr/bin/shortcuts
. Which I used in my script /usr/bin/shortcuts run shortcutname
.
What am I missing? Thanks in advance!