GameSprit

自転車やMac・AppleScript、映画・小説やドラマのレビュー、備忘メモ・クイズなどを置いています。

AppleScript:goo 辞書(国語辞典 英和辞典 和英辞典)検索を自動化

2008-09-07 01:33:21 | AppleScript
AppleScript:goo 辞書(国語辞典 英和辞典 和英辞典)検索を自動化 - GameSprit で作成した AppleScript を改良して、中日辞書 - エキサイト 辞書 を引くことができるようにしてみました。

エキサイトの中日辞書は、中国語あるいはピンインから引くことができますので、両方とも試してみました。


まず、中国語です。





コードのソース。

set searchWord to my URLencoding("明天")
--set searchWord to "mingtian"

set preF to "http://www.excite.co.jp/dictionary/chinese_japanese/?search="
set theMode to "&submit=+" & (my URLencoding("検") as string) & "+" & (my URLencoding("索") as string) & "+&match=beginswith"

open location (preF & searchWord & theMode) as string


on URLencoding(input)
set wordB4encode to input

set cmdPre to "echo "

--その他用(wikipedia、weblio)
set cmdSuf to "| iconv -t UTF-8 | perl -pe '~s/([^?w ])/\"%\".unpack(\"H2\", $1)/eg;'"

set theCompleteCmd to (cmdPre & wordB4encode & cmdSuf) as string
set wordAftEncode to (do shell script theCompleteCmd)

set org_delimi to text item delimiters of AppleScript
set text item delimiters of AppleScript to "%0a"
set wordAftEncode to text item 1 of wordAftEncode
set text item delimiters of AppleScript to org_delimi

return wordAftEncode
end URLencoding

-- on Leopard, Mac OS 10.5.4

『\』は本当は半角です。



実行結果。





ピンインで検索してみます。




コードのソース。

--set searchWord to my URLencoding("明天")
set searchWord to "mingtian"

set preF to "http://www.excite.co.jp/dictionary/chinese_japanese/?search="
set theMode to "&submit=+" & (my URLencoding("検") as string) & "+" & (my URLencoding("索") as string) & "+&match=beginswith"

open location (preF & searchWord & theMode) as string


on URLencoding(input)
set wordB4encode to input

set cmdPre to "echo "

--その他用(wikipedia、weblio)
set cmdSuf to "| iconv -t UTF-8 | perl -pe '~s/([^?w ])/\"%\".unpack(\"H2\", $1)/eg;'"

set theCompleteCmd to (cmdPre & wordB4encode & cmdSuf) as string
set wordAftEncode to (do shell script theCompleteCmd)

set org_delimi to text item delimiters of AppleScript
set text item delimiters of AppleScript to "%0a"
set wordAftEncode to text item 1 of wordAftEncode
set text item delimiters of AppleScript to org_delimi

return wordAftEncode
end URLencoding

-- on Leopard, Mac OS 10.5.4

『\』は本当は半角です。


実行結果(URLアドレスをみると、ピンインで検索していることがわかります)。


最新の画像もっと見る

post a comment

ブログ作成者から承認されるまでコメントは反映されません。