[Emacs]Carbon EmacsからDictionary.app(辞書)で単語を調べる
Carbon EmacsからDictionary.app(辞書)で単語を調べるEmacsLispを書いてみました。 .emacs.elに貼るなどして使ってみてください。
LeopardのDictionary.appで試しました。Leopard以前のDictionary.appでは動かないと思います(使う人もいないと思いますが)。TigerのDictionary.appでも動くそうです(情報:dageziさん)。
関数、my-search-at-dictionary-appをdefine-keyないしglobal-set-keyしてください。
regionを渡す場合は、transient-mark-modeをtにしてないとダメです。
AppleScriptでUI Scriptingしているので、「システム環境設定>ユニバーサルアクセス>補助装置にアクセスできるようにする」のチェックボックスをONにしないと動きませんし、do-applescript関数を使っていますのでCarbon Emacs依存だと思います。
(defun my-search-at-dictionary-app ()
""
(interactive)
(let* ((keyword (read-from-minibuffer
" keyword: "
(my-get-keyword)))
(encoded-keyword (encode-coding-string keyword 'japanese-shift-jis)))
(unless (string= encoded-keyword "")
(do-applescript (concat "
activate application \"Dictionary\"
tell application \"System Events\"
tell application process \"Dictionary\"
set value of text field 1 of group 1 of tool bar 1 of window 1 to \""
encoded-keyword "\"
click button 1 of text field 1 of group 1 of tool bar 1 of window 1
end tell
end tell
")))))
(defun my-get-keyword ()
""
(or (and
transient-mark-mode
mark-active
(buffer-substring-no-properties
(region-beginning) (region-end)))
(thing-at-point 'word)))
(transient-mark-mode t)
もちろん、「dict://」という独自スキーマがあることは知ってます。
open location "dict://test"でいけます。
いつか辞書切り替えをするかもな、ということでこうしてみました。
« [iPod touch]iPod touch / iPhone用ダウンローダHistoryDL.appで画像のダウンロードするのを補助するbookmarklet | Main | [iPod touch]iPod touchにマイクを付けて録音実験 »


Recent Comments