January 22, 2014

Emacs Mew Biff with MacOS X Notification Center

Google Notifier [google.com] がサンセットするらしい。以前は Mew の Biff [mew.org] 機能で新着メールを確認していたが、最近は Emacs が常に最前面に表示されているような生活でもないので、Mew から terminal-notifier [github.com] 経由で、MacOS X の Noficitaion Center (通知センター)に新着メールの到着を表示するようにした。

Homebrew で terminal-notifier をインストール。
$ brew install terminal-notifier
下記を .mew.el に追記し、mew-biff-bark をオーバーライト。
(defun mew-biff-bark (n)
  "Overwrite mew-biff-bark to invoke terminal-notifier to show a biff alert in MacOS X Notification Center"
  (if (= n 0)
      (setq mew-biff-string nil)
    (if (and mew-use-biff-bell (eq mew-biff-string nil))
 (call-process "/bin/bash" nil nil nil "-c" 
        (format "\/usr\/local\/bin\/terminal-notifier -message Mail\\\(%d\\\) -title Mew -sound Default -activate org\.gnu\.Emacs -sender org\.gnu\.Emacs -group Emacs.mew -remove Emacs.mew" n)))
    (setq mew-biff-string (format "Mail(%d)" n))))
オリジナルの mew-biff-bark の beep を terminal-notifier の呼び出しに置き換えたので、既に新着メールが1個以上あるときに更に新しいメールが来ても、通知はされない(五月蝿いからそういう仕様になってる!?)。
Mew 6.5, Emacs 24.3.1, terminal-notifier 1.5.1, OS X 10.9.1 で動作確認。

ちなみに、最近の Emacs は Desktop Notification [gnu.org] がサポートされているらしいが、freedesktop.org Desktop Notifications Specification のみの模様。

(January 23, 2014 追記; Gist Revision 2)
既に新着メールが1個以上あるときに更に新しいメールが来ても通知されないのは、Emacs のモードラインが常に見える状況ならよいかもしれないが、Notification Center の使い方としてはやはり不便なので、若干変更し Gist に置いた。

(January 30, 2014 追記; Gist Revision 3)
新着メールを Mew で取り込みモードラインの "Mail(n)" の表示を消す mew-buff-clear が呼び出されるときに、Notification Center の通知も消すように変更。

1 comment:

  1. Good post. I am experiencing a few of these issues as well..

    ReplyDelete

Note: Only a member of this blog may post a comment.