LoginSignup
0
2

【Mac】launchedの使用方法

Posted at

設定方法

用途ごとに設定ファイルを以下の場所に保存します。

場所 用途
~/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>
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2