說明
1. /System/Library/LaunchDaemons是用戶未登陸前就啟動的服務(守護進程)。
/System/Library/LaunchAgents是用戶登陸后啟動的服務(守護進程)。
2. /System/Library目錄是存放Apple自己開發的軟件。
/Library目錄是系統管理員存放的第三方軟件。
~/Library/是用戶自己存放的第三方軟件。
步驟
1. 首先創建一個自動任務的配置文件.plist,也可以從/System/Library/LaunchDaemons/獲取一個別的任務的plist文件,然后改改名字
比如命名為com.apple.wind-auto.plist
2. plist里面設定編譯時間方式
每小時啟動
<key>StartInterval</key>
<integer>60</integer>
每天每小時0分啟動
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>0</integer>
</dict>
每個周六的3點15分啟動
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>15</integer>
<key>Weekday</key>
<integer>6</integer>
</dict>
3. 拷貝到Libaray目錄下,例如:sudo cp /users/用戶/dev/iphone/project/com.apple.wind-auto.plist ./com.apple.wind-auto.plist
4. 啟動計划任務 sudo launchctl load -w /Library/LaunchDaemons/com.apple.wind-auto.plist
停止計划任務 sudo launchctl unload -w /Library/LaunchDaemons/com.apple.wind-auto.plist
注意: -w是不寫入disk
參考資料
http://www.netingcn.com/mac-os-plist.html
http://www.devdaily.com/mac-os-x/launchd-plist-examples-startinterval-startcalendarinterval
http://www.devdaily.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs