LoginSignup
8
7

More than 5 years have passed since last update.

vagrant-notify+terminal-notifierでvagrantからローカルに通知をする

Last updated at Posted at 2015-01-01

環境

  • ホストOS: MacOS10.10
  • Vagrant version: 1.6.3
  • ゲストOS: CentOS6.5

準備

vagrant-notifyをホストにインストール

$ vagrant plugin install vagrant-notify

*nokogiriのインストールでこけたら

インストールしようとすると以下のようなエラーが出て少しはまった

An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.5'` succeeds before bundling.

ログを見ると

libiconv is missing.  Please locate mkmf.log to investigate how it is failing.

libiconvが足りないそうなので、インストールする

$ brew tap homebrew/dupes
$ brew install libiconv

が、まだダメ。どうやらnokogiriのバージョンをシステムのものに明示的に指定しないとだめっぽいので以下のようにする

$ export NOKOGIRI_USE_SYSTEM_LIBRARIES=true

terminal-notifierをインストールする

$ brew install terminal-notifier

terminal-notifierの使用例

$ echo 'Piped Message Data!' | terminal-notifier -sound default
$ terminal-notifier -title '?' -message 'Check your Apple stock!' -open 'http://finance.yahoo.com/q?s=AAPL'

notify-sendスクリプトを作成する

$ cd /usr/local/bin
$ cd vim notify-send
$ sudo chmod u+x notify-send
#!/bin/zsh

terminal-notifier -title "$2" -message "$3" -sound default

vagrant上で通知スクリプトがちゃんと動くか確認する

$ vagrant up
$ vagrant ssh
$ notify-send title message

guardの通知と連携するためにスクリプト変更

#!/bin/bash
while getopts t:h:i:u:i:c: OPTION
do
  case $OPTION in 
    t) TIME=$OPTARG;;
    h) ;;
    i) IMAGE=$OPTARG;;
    u) ;;
  esac
done
shift `expr $OPTIND - 1`
MESSAGE=$*
terminal-notifier -title "$1" -message "$MESSAGE" -contentImage "$IMAGE" -sound default

8
7
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
8
7