設定方法
用途ごとに設定ファイルを以下の場所に保存します。
場所 | 用途 |
---|---|
~/Library/LaunchAgents/<Label>.plist |
ユーザー単位のエージェント |
/Library/LaunchAgents/<Label>.plist |
管理者が提供するユーザーごとのエージェント |
/Library/LaunchDaemons/<Label>.plist |
管理者によって提供されるシステム全体のデーモン |
以下のコマンドを実行すると定期実行されるようになります。
ターミナル
launchctl load /path/to/your.plist
以下のコマンドを実行すると定期実行されなくなります。
ターミナル
launchctl unload /path/to/your.plist
サンプル
30秒ごとにsample.shを実行
~/Library/LaunchAgents/sample.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>sample</string>
<key>Program</key>
<string>/Users/mofu/script/sample.sh</string>
<key>StartInterval</key>
<integer>10</integer>
<key>StandardOutPath</key>
<string>/Users/user_name/script/sample.out</string>
<key>StandardErrorPath</key>
<string>/Users/user_name/script/sample.err</string>
</dict>
</plist>
毎日3時にsample.shを実行
~/Library/LaunchAgents/sample.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>sample</string>
<key>Program</key>
<string>/Users/user_name/script/sample.sh</string>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>0</integer>
<key>Hour</key>
<integer>3</integer>
</dict>
<key>StandardOutPath</key>
<string>/Users/user_name/script/sample.out</string>
<key>StandardErrorPath</key>
<string>/Users/user_name/script/sample.err</string>
</dict>
</plist>