Pet*_*lan 4 path launchd plist
我目前正在使用 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)
谢谢!
使用 shell 作为 arg0 并为其提供相对于用户主文件夹的路径对我有用:
<key>ProgramArguments</key>
<array>
<string>zsh</string>
<string>-c</string>
<string>~/CLI/scripts/list_open_jira_tickets --skip=5297 > ~/CLI/tmp/open_jira_tickets.txt</string>
</array>
Run Code Online (Sandbox Code Playgroud)
如果守护进程作为每用户代理运行(安装在 ~/Library/LaunchAgent 中),您可以使用句点获取相对路径。哪个是主文件夹 ( ~/)
所以你可以这样做:
<key>Program</key>
<string>./Desktop/simple.sh</string>
Run Code Online (Sandbox Code Playgroud)
将程序保存在 plist 旁边可能会更好:
./Library/LaunchAgents/simple.sh
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1643 次 |
| 最近记录: |