Growl の Ruby バインディングを書いてみた

Growl SDK に入っている Ruby バインディングが、クリックやタイムアウトのイベント通知に対応してなかったので、自分で書いてみた。

http://limechat.net/rubycocoa/growl.rb

RubyCocoa アプリケーションの中で以下のように書くと、クリックやタイムアウトを検知できる。

require 'growl'

class GrowlController < OSX::NSObject
  def init
    @g = Growl::Notifier.alloc.initWithDelegate(self)
    @g.start('test_app', ['message_type'])
    self
  end

  def notify
    @g.notify('message_type', 'title', 'desc', 'click_context')
  end
  
  def growl_onClicked(context)
    puts 'clicked'
  end
  
  def growl_onTimeout(context)
    puts 'timeout'
  end
end

アプリケーションの中じゃなくて、ruby スクリプトとして動かすと通知がこないのは、NSRunLoop が動いてないからかな。