Created
March 13, 2022 05:40
-
-
Save wastu01/66d9c887c1dd2155fa09e98fa42dfd1b to your computer and use it in GitHub Desktop.
Mac-開機自動執行指令-Creating Launch Daemons and Agents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"> | |
<!-- # 載入任務 | |
launchctl load ~/Library/LaunchAgents/com.larry.launchctl.plist | |
# 移除任務 | |
launchctl unload ~/Library/LaunchAgents/com.larry.launchctl.plist | |
# 手動執行任務 | |
launchctl start com.larry.launchctl | |
# 列出所有任務 | |
launchctl list --> | |
<dict> | |
<key>Label</key> | |
<string>com.larry.launchctl.plist</string> | |
<key>ProgramArguments</key> | |
<array> | |
<!-- <string>/Users/wa.01/Desktop/預算及計帳.numbers</string> --> | |
<string>/Users/wa.01/Desktop/python/python.py</string> | |
</array> | |
<!-- <key>StartCalendarInterval</key> | |
<dict> | |
<key>Minute</key> | |
<integer>35</integer> | |
<key>Hour</key> | |
<integer>13</integer> | |
</dict> --> | |
<!-- 運行間隔,與StartCalenderInterval使用其一,單位爲秒 --> | |
<key>StartInterval</key> | |
<integer>3</integer> | |
<key>KeepAlive</key> | |
<false/> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>StandardOutPath</key> | |
<string>/tmp/AutoMakeLog.log</string> | |
<key>StandardErrorPath</key> | |
<string>/Users/wa.01/Desktop/python/log.err</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
import datetime | |
def add(path, content): | |
with open(path,'a') as f: | |
f.write(content + '\n') | |
path = '/Users/wa.01/Desktop/python/text/index.text' | |
now_time = "{}".format(datetime.datetime.now()) | |
add(path, now_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment