Macの日本語IM用辞書ファイルをGoogle IMEの辞書ファイルに変換する

Macの日本語IM用ユーザー辞書ファイル(.plist)をGoogle IMEのユーザー辞書ファイル(.txt)に変換するスクリプトです。
対象のファイルを選択して、スクリプトエディタ上またはスクリプトメニューから実行するか、アプリケーションとして保存するとスクリプトアプリケーションに投げ入れて実行できます。

Macのユーザー辞書の構造上“品詞”が用意されていないので、変換するGoogle IMEはデフォルトで“名詞”としています。必要に応じて辞書上で変更してください。

on main(myFiles)
repeat with i in myFiles
tell application "Finder" to set anExt to name extension of i
if anExt = "plist" then
set aContent to do shell script "cat " & (quoted form of POSIX path of i)
set aContent to text (offset of "<array>" in aContent) thru -9 of aContent
set keyList to {}
repeat with i from 1 to (length of (paragraphs of aContent))
if item i of (paragraphs of aContent) contains "<string>" then
set the end of keyList to replaceText(replaceText(item i of (paragraphs of aContent), " <string>", "") of me, "</string>", "") of me
end if
end repeat
set bList to {}
repeat with i from 2 to (length of keyList) by 2
set aList to {(item i of keyList) & " " & (item (i - 1) of keyList) & " 名詞"}
set the end of bList to aList
end repeat

if (length of bList > 0) then
set uuid to do shell script "uuidgen"
do shell script "touch ~/Desktop/" & uuid & ".txt"
repeat with i in bList
do shell script "echo " & (quoted form of (i as text)) & " >> ~/Desktop/" & uuid & ".txt"
end repeat
end if
end if
end repeat
end main

on run
tell application "Finder" to return my main(the selection as alias list)
end run

on open dropedFiles
return my main(dropedFiles)
end open

--任意のデータから特定の文字列を置換
on replaceText(origData, origText, repText)
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {origText}
set origData to text items of origData
set AppleScript's text item delimiters to {repText}
set origData to origData as text
set AppleScript's text item delimiters to curDelim
return origData
end replaceText

更新履歴

inserted by FC2 system