LoginSignup
17
17

More than 5 years have passed since last update.

launchdを使ってhomebrewを自動更新(update/upgrade)

Posted at

launchdを使ってhomebrewを自動更新(update/upgrade)

パッケージ管理システムのhomebrewを使用していますが、updateやupgradeを自身でやるのが面倒なので、launchdを使って自動化します。

環境

macOS Sierra(10.12.5)

事前準備

定期実行にはlaunchdを使用しますが、更新が完了したことを通知したいので、terminal-notifierも使用します。これもhomebrewでインストールします。

$ brew install terminal-notifier

plistファイル作成

以下内容のファイルを~/Library/LaunchAgents/localhost.homebrew-upgrade.plistという名前で作成します。

※ 起動時、または6時間毎に実行するようにしてます。

<?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>localhost.homebrew-upgrade</string>
    <key>ProcessType</key>
    <string>Background</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>-c</string>
        <string>/usr/local/bin/brew update &amp;&amp; /usr/local/bin/brew upgrade &amp;&amp; /usr/local/bin/terminal-notifier -title 'homebrew' -message 'homebrew upgraded'</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/localhost.homebrew-upgrade.stderr</string>
    <key>StandardOutPath</key>
    <string>/tmp/localhost.homebrew-upgrade.stdout</string>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>6</integer>
    </dict>
</dict>
</plist>

launchdに登録

以下を実行

launchctl load ~/Library/LaunchAgents/localhost.homebrew-upgrade.plist

launchdから削除

以下を実行

launchctl unload ~/Library/LaunchAgents/localhost.homebrew-upgrade.plist
17
17
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
17
17