notify-sendについて調べたのでメモ
Ubuntu(9.10 Karmic Koara)での話。
- notify-sendというコマンドを知りました
自分の環境ではCommand Not Foundだったので、インストール。
hibariya@HIBARIYA% aptitude install libnotify-bin hibariya@HIBARIYA% notify-send 'summary' 'body'
デフォルトでは画面の右上にGrowlみたいなのが出てきて、なかなか素敵。
- Pythonでできるそうです
import pynotify pynotify.init("notify-example") n = pynotify.Notification( "notify-example", "Hello, NotifyOSD", "notification-message-IM") n.show()http://kamenasu.blogspot.com/2009/08/pythonnotifyosd.html
すごい!
- Rubyでもやってみたい
hibariya@HIBARIYA% gem search -r libnotify *** REMOTE GEMS *** libnotify (0.0.4)
なんだかそれらしいものが。
libnotifyにはFFIも必要らしいので、一緒にインストール。
hibariya@HIBARIYA% sudo gem install libnotify ffi Successfully installed libnotify-0.0.4 Building native extensions. This could take a while... Successfully installed ffi-0.5.4 2 gems installed Installing ri documentation for libnotify-0.0.4... Installing ri documentation for ffi-0.5.4... Installing RDoc documentation for libnotify-0.0.4... Installing RDoc documentation for ffi-0.5.4... hibariya@HIBARIYA% sudo updatedb hibariya@HIBARIYA% locate libnotify.rb /usr/lib/ruby/gems/1.8/gems/libnotify-0.0.4/lib/libnotify.rb /usr/lib/ruby/gems/1.8/gems/libnotify-0.0.4/test/test_libnotify.rb
使い方も何も知らないので、中身を覗いてみる。
libnotify.rbは/usr/lib/ruby/gems/1.8/gems/libnotify-0.0.4/libにあるみたい。
どんどこスクロールしていくと、ファイルの最後あたりにサンプルコードがあった。
Libnotify.new do |notify| notify.summary = "world" notify.body = "hello" notify.timeout = 1.5 # 1.5 (sec), 1000 (ms), "2", nil, false notify.urgency = :critical # :low, :normal, :critical notify.icon_path = "/usr/share/icons/gnome/scalable/emblems/emblem-default.s notify.show! end Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
早速見よう見まねでで動かそうとしたら、何かのライブラリが足りないと(何だったか忘れた)怒られたので、libnotify-devをインストール。
hibariya@HIBARIYA% aptitude install libnotify-dev
↓みたいに色々省略してもOK。
#!/usr/bin/env ruby require 'rubygems' require 'libnotify' Libnotify.show{|n| n.summary = 'どうのこうの' n.body = 'あーしてこーして' }
rubygemsをrequireしたり環境によってはlibnotify-devをインストールしなきゃいけなかったりするので、普通にシェル叩いた方が楽な気もするけど、満足できたのでOK。