要设置特定作业的环境,您应该使用
EnvironmentVariables作业定义本身中的键:
<?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.example.app</string> <key>Program</key> <string>/path/to/your/script</string> <key>EnvironmentVariables</key> <dict> <key>PYTHONPATH</key> <string>/your/python/path</string> </dict></dict></plist>
您可以
launchd(8)通过编辑
/etc/launchd.conf守护程序或
/etc/launchd-user.conf代理来定义服务的默认环境变量。后者有效,但未记录。当前记录的(但不受支持的)每用户配置文件为
$HOME/.launchd.conf。
这些配置文件包含
launchctl(1)子命令列表。您想要的是:
setenv PYTHonPATH /your/python/path
更新:
/etc/launchd.confMac OS X 10.10及更高版本不支持。在这些系统上,您必须基于每个作业定义环境变量。



