我有一个 Python 脚本,我想在登录 Mac 后立即执行该脚本。我在互联网上尝试了各种方法。但它们似乎都不起作用。
我尝试将com.username.scriptname.plist
文件放在 Library/LaunchAgents 中。
<?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.username.scriptname</string>
<key>Program</key>
<string>/Users/username/scriptlocation/scriptname.py</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/com.username.scriptname.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.username.scriptname.out</string>
</dict>
</plist>
我将脚本放在.plist
文件中提到的位置,然后运行以下命令
launchctl load /Library/LaunchAgents/com.username.scriptname.plist
。然而似乎什么也没发生。我是否错过了任何步骤或做错了什么?我需要更改任何设置吗?
错误:
->grep com.username.scriptname /var/log/syslog
grep: /var/log/syslog: No such file or directory
->launchctl list com.username.scriptname
{
"StandardOutPath" = "/tmp/com.username.scriptname.out";
"LimitLoadToSessionType" = "Aqua";
"StandardErrorPath" = "/tmp/com.username.scriptname.err";
"Label" = "com.username.scriptname";
"TimeOut" = 30;
"OnDemand" = true;
"LastExitStatus" = 19968;
"Program" = "/Users/username/scriptname.sh";
};
当我有一个 Python 文件时,它显示 scriptname.sh 的方式很奇怪!