3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Homebrew の アップデートを自動化

Last updated at Posted at 2022-01-18

環境

M1 macに対応しました。

macOS Catalina

plistファイルを作成します

~/Library/LaunchAgents/に下記ファイルを作成します。

ファイル名はlocalhost.homebrew-autoupdate.plistとしました。

このplistで前回のアップデートから8時間経過または起動時に自動的に

brew update

brew upgrade

brew cleanup

の三つのコマンドが実行されるようにしました!

Intel mac


<?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-autoupdate</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/brew cleanup &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>8</integer>
 </dict>
</dict>
</plist>

M1 mac


<?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-autoupdate</string>
  <key>ProcessType</key>
  <string>Background</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/sh</string>
    <string>-c</string>
    <string>
      /opt/homebrew/bin/brew update &amp;&amp;
      /opt/homebrew/bin/brew upgrade &amp;&amp;
      /opt/homebrew/bin/brew cleanup &amp;&amp;
      /opt/homebrew/bin/terminal-notifier -title 'Homebrew' -message 'Homebrew updated!'
    </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>8</integer>
  </dict>
</dict>
</plist>

動作確認

下記コマンドを実行してOKと表示されることを確認してください!

plutil -lint ~/Library/LaunchAgents/localhost.homebrew-autoupdate.plist​

launchdに登録

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

launchctl list でlaunchdに登録されているリストを表示してlocalhost.homebrew-autoupdate
があることを確認

launchctl list | grep home
3
1
2

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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?