bear icon indicating copy to clipboard operation
bear copied to clipboard

Launchctl "command not found: bear"

Open usizu opened this issue 4 years ago • 3 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.

usizu avatar Dec 20 '20 14:12 usizu

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.

usizu avatar Dec 20 '20 16:12 usizu

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 avatar Dec 20 '20 17:12 usizu

@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!

sloansparger avatar Dec 21 '20 15:12 sloansparger