LauncyとGrowlを使って必要なときにサッっと英和辞書を引くためのスクリプトを書いた

またもGfWネタ

http://gyazo.com/8248ac1329d314d54200f1ebe67dd350.png

Launchyからオンラインの辞書(英辞郎)を引く事ができる。
結果はGrowlで通知される。

http://gyazo.com/1405f110232f1d92b52a3c8fd021ca0a.png

コード

require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'ruby_gntp'

word = ARGV[0]

def growl(title, text)
  GNTP.notify(
    :app_name => "Dicty",
    :title    => title,
    :text     => text,
    :icon     => Dir.pwd + '\Book.png'
  )
end

doc = Nokogiri::HTML(open("http://eow.alc.co.jp/#{word}/utf-8"))

result_item = doc.css("div#resultList > ul > li[1]")
result_word = result_item.css("span.midashi").text
result_body = ""

result_item.css("div").css("span.wordclass, ol>li").each {|line|
  if result_body != "" && line.name == "span"
    growl result_word, result_body
    result_body = ""
  end

  result_body << "#{line.text}\r"
}
growl result_word, result_body if result_body != ""

これを "dicty.rb" とか適当な名前で保存して、 以下のように launchy の runny プラグインに登録する。

http://gyazo.com/8873ce275c7e6cb955cde6e86fe7393d.png

追記:2009/7/7 動作に必要なgem

翻訳結果のスクレイピングでnokogiriが、Growl for Windows への通知で拙作ruby_gntpが必要です。
RubyGemsの入っている環境で、

gem install nokogiri -r
gem install ruby_gntp -r

でインストールしといてください。