快適 Growl 術

Growl

Growl 使ってますか!Mac ユーザーの皆さん、Growl が OS X の標準機能ではないことに驚いたのも一度や二度ではありませんね!そういえば Windows 版もありますけど、使ったことないからよく知りません。

最近、Mac App Store から “Growl 1.3” がリリースされました。OS X Lion 以降に対応して170円。これを活用する『快適 Growl 術』をいくつか紹介します。


Growl があれば色んな通知が画面の端っこに表示されてとっても便利なわけですが、そもそも Growl に対応しないアプリケーションもいっぱいあります。そう、Apple 純正のアプリケーションとか。

Mail と iChat を Growl

Apple 製の Mail.app と iChat.app で Growl しちゃいましょう。この二つのアプリケーションが Growl したらとっても便利です。GrowlMail は本体から分離されましたからここでは取り上げません。AppleScript を使いましょう。

Mail

Mail

using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
set the message_count to the count of these_messages
repeat with i from 1 to the message_count
set this_message to item i of these_messages

-- GET THE SENDER OF THIS MESSAGE
set this_sender to the sender of this_message
-- GET SUBJECT OF MESSAGE
try
set this_subject to (subject of this_message) as Unicode text
if this_subject is "" then error
on error
set this_subject to "NO SUBJECT"
end try
-- GET CONTENT OF MESSAGE
try
set this_content to (every character of content of this_message) as Unicode text
if this_content is in {"", "?"} then error
on error error_message
set this_content to "NO CONTENT"
end try

-- display Growl notification
tell application "Growl"

set allNotificationsList to {"New Message"}
set enableNotificationsList to {"New Message"}

register as application "Mail" all notifications allNotificationsList default notifications enableNotificationsList
notify with name "New Message" title (this_subject & " — " & this_sender) description this_content application name "Mail"

end tell

end repeat
end tell
end perform mail action with messages
end using terms from

Growl with Mail

iChat

IChat

using terms from application "iChat"
on message received this_message from this_buddy for this_chat

set this_name to the name of this_buddy

set this_image to the image of this_buddy

try
set this_subject to the subject of this_chat
if this_subject is missing value then error
on error
set this_subject to "NO SUBJECT"
end try

-- display Growl notification
tell application "Growl"

set allNotificationsList to {"New Message"}
set enableNotificationsList to {"New Message"}

register as application "iChat" all notifications allNotificationsList default notifications enableNotificationsList
if this_image is not missing value then
notify with name "New Message" title (this_name & " — " & this_subject) description this_message application name "iChat" image this_image
else
notify with name "New Message" title (this_name & " — " & this_subject) description this_message application name "iChat"
end if

end tell

end message received
end using terms from

Growl with iChat

それぞれ上記のように設定しましょう。これで良い感じに Growl されますね。ちなみにこれらは Growl 1.3 と OS X Lion で動きます。古いバージョンだとちょっと変えないと動かないと思います。


適当なスクリプトを書いてコンピュータに仕事させるとき、どこまで進んでいるのか、処理が終わったのか、いちいち確認するのも面倒。そう、Growl させちゃえば良いですね。Growl 1.3 なら “GNTP (Growl Notification Transport Protocol)” に対応しています。これはネットワーク経由の通知を可能にし、さらに Windows 版とも互換性があります。これを使いましょう。

Python と Ruby から通知

Python でも Ruby でも、GNTP を利用して Growl するためのライブラリが公開されています。それを用いて、ライブラリがインストールされていれば Growl 通知し、そうでなければ標準出力にメッセージを表示するメソッドを定義してみましょう。

Python

Python

Python では gntp モジュールを使います。

pip install gntp
def notify(title, message):
    try:
        import gntp.notifier

        growl = gntp.notifier.GrowlNotifier(
            applicationName="Python/GNTP",
            notifications=["notify"]
        )
        growl.register()

        growl.notify(
            noteType="notify",
            title=title,
            description=message
        )
    except ImportError:
        print(title + ": " + message)

notify("Title", "Message")

Ruby

Ruby

Ruby では ruby_gntp クラスを使います。

gem install ruby_gntp
def notify(title, message)
  begin
    require 'ruby_gntp'

    growl = GNTP.new("Ruby/GNTP")
    growl.register(:notifications => [{
      :name     => "notify"
    }])

    growl.notify(
      :name  => "notify",
      :title => title,
      :text  => message
    )
  rescue LoadError
    puts "#{title}: #{message}";
  end
end

notify('Title', 'Message')

これでタイトルとメッセージを通知できました。ライブラリがない場合でも何となく使える感じですね。GNTP を使っているので Windows でも動くはずです。


Automator

Automator

Automator からも Growl できます。簡単ですね。

Automator


気付かないといけないことに気付くことのできない皆さん、知らないうちに大切なことは過ぎ去っていきます。がんがん Growl していきましょう!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>