问题
Why won't launchd load my zsh program? I'm befuddled. My testplisterror.log gives me this error:
/bin/zsh: can't open input file: /Users/controlroom/Desktop/Bin/testplist.zsh -- below is my com.testplist.plist file located in the LaunchAgents directory.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.testplist.plist</string>
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>/Users/controlroom/Desktop/Bin/testplist.zsh</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
<key>StandardOutPath</key>
<string>/Users/controlroom/Desktop/testplist.log</string>
<key>StandardErrorPath</key>
<string>/Users/controlroom/Desktop/testplisterror.log</string>
</dict>
</plist>
Here is my testplist.zsh file:
#!/bin/zsh
date >> ~/Desktop/launchdtest.txt
回答1:
So this is because of a TCC error but because a script doesn't have a GUI you won't get an error. So as stated from Gordan Davisson, Apple has some TTC guidelines. These specific folders are TCC protected in Catalina:
~/Desktop, ~/Documents, ~/Downloads, iCloud Drive,
third-party cloud storage, if used, removable volumes, network volumes.
https://eclecticlight.co/2020/01/16/a-guide-to-catalinas-privacy-protection-3-new-protected-locations/
"Logic would suggest that you could add the script to the Full Disk Access list, but I think you’ll find that you can’t, because it only accepts apps and executables." So the snag here is that currently you can't add a .zsh script to Full Disk Access List because of Apples TCC."
回答2:
Okay first, in order to launchd to grab a file you must add:
<key>UserName></key>
<string>usernamehere</string>
In other words, the program has to run as a username—if you don't have this it won't find the file.
Second, you must add:
<key>GroupName</key>
<string>wheel</string>
Third -- sometimes 3rd party commands won't execute properly in your script unless you add the
<key>EnvironmentalVariables</key>
<key>PATH</path>
<string>/usr/local/bin:...etc.</string>
For one reason or another it can't find executables of 3rd party CLI apps if you don't have this present in your script.
Because the syntax can be difficult and error prone I highly suggest using LaunchControl app to do this. It is an extremely useful piece of software!
来源:https://stackoverflow.com/questions/64419734/macos-catalina-launchd-cant-open-input-file-error