Launchctl "command not found: bear"
usizu opened this issue · comments
Hi,
I've made a shell script that uses Bear CLI to make custom journal entries for me, and I want to run these daily with launchctl. The script works when I run it from terminal, but when I run it with launchctl I get errors: "command not found: bear" on the lines that execute the Bear CLI commands.
It seems launchctl doesn't have permission to run Bear CLI?
The two lines in question:
noteId=$(bear create " " -n=${printDate})
noteNew=$(bear add-text ${journal} --id=${noteId} --mode=replace_all)
I tried giving Bear CLI Full Disk Acccess in System Preferences -> Security & Privacy but that didn't help. I'm quite new to scripting, terminal and launchd. Thanks for any tips.
I've seen it suggested in other threads (https://superuser.com/questions/1044228/unable-to-load-script-via-launchctl-command-not-found#1044245) that "command not found" is because if a script is run by launchctl then it needs the absolute path. In the case of Bear CLI what would that be? I tried /Users/myuser/path-to-Bear-CLI-project/bin/run
but that gives the error "env: node: No such file or directory", and I tried pointing /usr/local/lib/node_modules/@sloansparger/bear
and /bear/bin/
but those gave me a permissions error, even when running launchctl with sudo.
Ok it turns out adding export PATH=$PATH:/usr/local/bin
to my script was able to fix the paths. Hopefully that will be useful to anyone else trying to get this to work with launchctl.
@usizu thanks for walking through the problem and solution. Like you said, this isn’t the first time someone has hit this issue, so I’ll go ahead and add it to the README so others benefit!