Mac の iTerm2 でコマンドが終了したら通知する方法を紹介します。時間がかかるコマンドを実行しながら、別の作業をやりたいときなどにおすすめの方法です。以前は terminal-notifier と zsh プラグインで実現していたのですが、いつの間にか iTerm2 の標準機能でできるようになっていました。iTerm2 のバージョンは 3.4.3 で動作確認をしています。
以前の terminal-notifier と zsh プラグイン版はこちら。
-
-
Macのターミナルで時間がかかるコマンドが終了したら通知する
Mac で時間がかかるコマンドを実行し、コマンドが終了したら通知する方法を紹介します。コマンドを実行している間に他の作業 ...
続きを見る
目次
Shell Integration をインストール
Shell Integration をインストールします。iTerm2 の上部メニューから iterm2 > Install Shell Integration を選択し、ウィザードを進めます。

ウィザードを進めると以下のコマンドが実行され Shell Integration がインストールされます。
curl -L https://iterm2.com/shell_integration/install_shell_integration.sh | bash
Alerts Post Notification にチェックをいれる
iTerm2 の上部メニューから Edit > Marks and Annotations > Alerts > Post Notification にチェックをいれます。

コマンドの終了で通知をする
上部メニューから Edit > Marks and Annotations > Alerts > Post Notification を選択します。ショートカットキーの command + option + A キーが便利です。

選択をすると、右上に目玉のアイコンが表示されます。この状態で何かコマンドを実行してみましょう。通知が送信されれば OK です。
sleep 3
通知だと見逃してしまうという方はモーダルアラートにすることもできます。
おわりに
コマンドの実行時に、毎回 command + option + A キーでマークを設定する必要はあるのですが、プラグインなどを使わずに iTerm2 の標準機能だけで通知ができるようになったのは良いですね。ご検討ください。