Skip to content

Instantly share code, notes, and snippets.

@wastu01
Created March 13, 2022 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wastu01/66d9c887c1dd2155fa09e98fa42dfd1b to your computer and use it in GitHub Desktop.
Save wastu01/66d9c887c1dd2155fa09e98fa42dfd1b to your computer and use it in GitHub Desktop.
Mac-開機自動執行指令-Creating Launch Daemons and Agents
<?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>
#!/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