HOME > AppleScript > gooDict の検索結果を標準テキスト書類として書き出す


(*Mac OS X 10.4.5 (on PPC)、gooDict 2.2 で動作確認。

gooDict - Spread Your Wings
http://homepage.mac.com/nsekine/SYW/top.html*)

tell application "System Events"

if not (exists application process "gooDict") then
beep
return
else
activate application "gooDict"
end if

tell process "gooDict"
set searchResult to (value of text area 1 of scroll area 1 of window 1)
if searchResult is "" or (paragraph 1 of searchResult) is "該当する検索結果はありません" then
beep
tell application "gooDict" to display dialog "検索結果がありません" buttons {"キャンセル"} default button 1 giving up after 1
return
else
set searchResult to searchResult & return & return & "===goo 辞書===" & return & "http://dictionary.goo.ne.jp/" & return
set searchMode to (value of pop up button 1 of window 1)
set fileName to (value of combo box 1 of window 1) & " (goo " & searchMode & "辞書).txt"
end if
end tell

end tell

tell application "gooDict"

activate
set filePath to (choose file name default name fileName)

--テキストの書き出し 1 (Shift JIS)
set theFile to open for access filePath with write permission
try
set searchResult to (searchResult as text)
write searchResult to theFile
close access theFile
on error
close access theFile
end try

--テキストの書き出し 2 (UTF-8)
--do shell script "echo " & quoted form of searchResult & " > " & quoted form of (POSIX path of filePath)

--テキストの書き出し 3 (UTF-16)
--do shell script "echo " & quoted form of searchResult & " | iconv -f UTF-8 -t UTF-16 > " & quoted form of (POSIX path of filePath)

set theResult to button returned of (display dialog "完了" buttons {"Finder で表示", "OK"} default button 2)

end tell

tell application "Finder"
if theResult is "Finder で表示" then
activate
reveal filePath
end if
end tell

HOME > AppleScript > gooDict の検索結果を標準テキスト書類として書き出す

TOP

created: 2006-03-15T20:02:46+09:00
last modified: 2006-04-04T00:35:08+09:00
author: AquaBowler