我正在尝试使用launchctl在mac中为getintraday.py设置一个自动程序。
1.创建run.sh
转到 getintraday.py 目录
cd /Users/yindeyong/Desktop/Django_Projects/pythonstock
vi run.sh
以下是run.sh:
#!/bin/sh
# record start time
echo `date` >> /Users/yindeyong/Desktop/Django_Projects/pythonstock/log &&
# go to getintraday.py directory
cd /Users/yindeyong/Desktop/Django_Projects/pythonstock &&
# Execute python scripts according to my virtual environment
/Users/yindeyong/Desktop/Django_Projects/envs/stockenv/bin/python3.6 getintraday.py
# Execute done
echo 'finish' >> /Users/demo/log/Users/yindeyong/Desktop/Django_Projects/pythonstock/log
然后保存并相当
:wq
chmod 777 run.sh
2.创建plist文档
去~/Library/LaunchAgents,创建com.demo.plist
以下是创建 com.demo.plist:
<?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>
<!-- Label -->
<key>Label</key>
<string>com.demo.plist</string>
<!-- the script to Execute -->
<key>ProgramArguments</key>
<array>
<string>/Users/yindeyong/Desktop/Django_Projects/pythonstock/run.sh</string>
</array>
<!-- the time to Execute -->
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>37</integer>
<key>Hour</key>
<integer>10</integer>
</dict>
<!-- Standard output file -->
<key>StandardOutPath</key>
<string>/Users/yindeyong/Desktop/Django_Projects/pythonstock/run.log</string>
<!--
Standard error output file, error log -->
<key>StandardErrorPath</key>
<string>/Users/yindeyong/Desktop/Django_Projects/pythonstock/run.err</string>
</dict>
</plist>
加载命令
launchctl 加载 -w com.demo.plist
但我得到/Users/yindeyong/Desktop/Django_Projects/pythonstock/com.demo.plist: No such file or directory