我有一个非常简单的测试脚本,我希望我的计算机每 60 秒运行一次 - time_test_script.py
. 该脚本只是将.txt
当前时间的文件保存为名称并将一些文本写入文件。该文件在/Users/me/Documents/Python
目录中。
import datetime
import os.path
path = '/Users/me/Desktop/test_dir'
name_of_file = '%s' %datetime.datetime.now()
completeName = os.path.join(path, name_of_file+".txt")
file1 = open(completeName, "w")
toFile = 'test'
file1.write(toFile)
file1.close()
print datetime.datetime.now()
我还有一个.plist
文件——test.plist
在/Library/LaunchAgents
目录中。
test.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>
<key>Label</key>
<string>com.test</string>
<key>ProgramArguments</key>
<array>
<string>/Users/me/Documents/Python/time_test_script.py</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
如果我手动运行脚本,它工作正常,即.txt
在指定目录中创建一个文件。但是,当我尝试launchctl
从终端启动时,什么也没有发生。
$ launchctl load /Library/LaunchAgents/test.plist
$ launchctl start com.test
我究竟做错了什么?