我目前正在使用 plist 来运行 shell 脚本。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.name.set</string>
<key>Program</key>
<string>/Users/username_here/Desktop/simple.sh</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>5</integer>
<key>StandardErrorPath</key>
<string>/tmp/com.name.example.stderr</string>
<key>StandardOutPath</key>
<string>/tmp/com.name.example.stdout</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
这有效!但是当我将程序名称更改为
<string>/Desktop/simple.sh</string>
Run Code Online (Sandbox Code Playgroud)
它不运行脚本。也~/Desktop/simple.sh不起作用。
有没有办法在不知道用户名和使用绝对路径的情况下运行脚本?
当我 tail launchd 时,我也收到此错误消息。
com.apple.xpc.launchd[1] (com.name.example[8178]): Service could not initialize: 14F27: xpcproxy + 13421 [1402][AD0301C4-D364-31CE-8BA7-B5DBECE64D0A]: 0x2
Run Code Online (Sandbox Code Playgroud)
谢谢!