launchctl plist has a stderr that talks about how getcwd operation not permitted so how do I fix it?
Analysis
After a long chat session, it turns out that the root of the problem was that bash
can't fully access the Documents folder. The OP had shortened the actual path for makeTodaySym.sh
: instead of being located in /Users/kim/journals
, the script resides in a subfolder of ~/Documents
.
The Documents folder is sandboxed, as explained in this Apple document:
In macOS, data in critical areas is itself sandboxed — which ensures that users remain in control of access to files in Desktop, Documents, Downloads and other areas from all apps, whether the apps attempting access are themselves sandboxed or not.
and bash
can't read its contents from within the .plist
file.
Two solutions
Place the script outside of ~/Documents
Interestingly enough, although bash
can't read the contents of the Documents folder, it can write to it.
So one solution is to move makeTodaySym.sh
outside of ~/Documents
. For instance, if placed in /Users/kim/bin/makeTodaySym.sh
, this should work:
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>/Users/kim/bin/makeTodaySym.sh /Users/kim/Documents/Apps/CompanyLevelApps/OILD/16-journals</string>
(Tested on macOS 10.15.5 Catalina.)
Grant full disk access to bash
Another solution is give bash
full disk access. Just add /bin/bash
to System Preferences>Security & Privacy>Privacy>Full Disk Access.
Note that even with full disk access, permissions would prevent bash
from reading arbitrary files in the file system, but you have one fewer level of protection.
(Tested on macOS 10.15.5 Catalina.)
Two suggestions
I'd suggest that you do the following two changes to your configuration:
Remove reference to working directory
I've noticed that setting a working directory in the .plist
file:
<key>WorkingDirectory</key>
<string>/Users/kim/Documents/Apps/CompanyLevelApps/OILD/16-journals</string>
causes this error:
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
Your script doesn't need the WorkingDirectory
key to successfully create the symlink, so you may want to remove it to get rid of the error.
Create symlink with relative path
Your script creates the symlink:
ln -sf "$file" "$folder/today.md"
with an absolute path:
today.md@ -> /Users/kim/Documents/Apps/CompanyLevelApps/OILD/16-journals/2020-06-10 Wednesday.md
To may want to use:
ln -sf "$(basename "$file")" "$folder/today.md"
instead to create a relative symlink that is easier to read:
today.md@ -> 2020-06-10 Wednesday.md
Full path in plist file
It's important to note that providing the full path for makeTodaySym.sh
(as explained in jksoegaard's answer) was a necessary change for the .plist
to work properly, as relative paths are not supported.
You need to change this:
<string>./makeTodaySym.sh</string>
so that you refer the whole path to the file. That could for example be like this:
<string>/Users/kim/journals/makeTodaySym.sh</string>