mat*_*pie 29 mac-osx osx-leopard environment-variables launchd
我很好奇是否可以ProgramArguments在 Mac OS X Leopard 上的 luanchd 脚本部分指定环境变量。
<?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>me.mpietz.MountDevRoot</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>$HOME/bin/attach-devroot.sh</string>
<!-- Instead of using...
<string>/Users/mpietz/bin/attach-devroot.sh</string -->
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
Joe*_*ock 24
不在 ProgramArguments 键中。您需要EnvironmentVariables在 plist 的 dict 中添加一个键,如下所示:
<?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>EnvironmentVariables</key>
<dict>
<key>AN_ENVIRONMENT_VARIABLE_NAME</key>
<string>the_value</string>
</dict>
<key>Label</key>
<string>me.mpietz.MountDevRoot</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>$HOME/bin/attach-devroot.sh</string>
<!-- Instead of using...
<string>/Users/mpietz/bin/attach-devroot.sh</string -->
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
请参阅:创建启动守护程序和代理。
小智 6
处理这个问题的最佳方法是将命令包装在 shell 中。例如:
\n\n<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n <key>KeepAlive</key>\n <false/>\n <key>Label</key>\n <string>sh.daniel.envvar</string>\n <key>ProgramArguments</key>\n <array>\n <string>/bin/zsh</string>\n <string>-c</string>\n <string>echo \'You did the thing!\' > $HOME/did-the-thing.log</string>\n </array>\n <key>RunAtLoad</key>\n <true/>\n</dict>\n</plist>\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x9d\xaf cat ~/did-the-thing.log\nYou did the thing!\nRun Code Online (Sandbox Code Playgroud)\n\n该标志-c告诉 ZSH(以及 Bash 和 sh)运行 next.txt 中指定的命令。如果添加标志-l,它\xe2\x80\x99 将在执行之前加载你的点文件,就像普通的登录 shell 一样。
我不确定 - 我以前没有尝试过......但我可以告诉你,如果你关心的唯一变量是 home - 你可以使用 ~.
So: <string>~/bin/attach-devroot.sh</string>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19078 次 |
| 最近记录: |