Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Path 启动层中的相对路径_Path_Plist_Launchd - Fatal编程技术网

Path 启动层中的相对路径

Path 启动层中的相对路径,path,plist,launchd,Path,Plist,Launchd,我目前正在使用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>

我目前正在使用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>

谢谢

如果守护进程作为每用户代理运行(安装在~/Library/LaunchAgent中),则可以使用句点获取相对路径。哪个将是主文件夹(
~/

所以你可以这样做:

<key>Program</key>
<string>./Desktop/simple.sh</string>

将shell用作arg0并为其指定相对于用户主文件夹的路径对我来说很有用:

编程参数
zsh
-c
~/CLI/scripts/list\u open\u jira\u tickets--skip=5297~/CLI/tmp/open\u jira\u tickets.txt

在这种情况下,转换为
/
,而不是
~
。您尝试过吗?我的cron工作就是这样的。如果您的脚本是用户代理(因此位于主文件夹的库中),
launchd
的当前工作目录是主文件夹。我确实在macOS 10.12(Sierra)上用户的
LaunchAgents
目录中尝试过,并将其转换为
//code>。将脚本保存在plists旁边似乎是个糟糕的主意,所以你不一定想要不属于你的东西。
com.apple.xpc.launchd[1] (com.name.example[8178]): Service could not initialize: 14F27: xpcproxy + 13421 [1402][AD0301C4-D364-31CE-8BA7-B5DBECE64D0A]: 0x2
<key>Program</key>
<string>./Desktop/simple.sh</string>
./Library/LaunchAgents/simple.sh