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

GoogleIMEの辞書ファイル(*.txt)をMacの日本語IM用辞書ファイル(*.plist)に変換するスクリプトです。
アプリケーションとして保存すればドロップレットとして動作し、*.txtファイルを投げ込めば変換されます。
スクリプトメニューやスクリプトエディタ上からも実行できます。

on main(myFiles)
repeat with i in myFiles
set aFile to POSIX path of (contents of i)
if extCheck(aFile) then
set aDict to do shell script "cat " & (quoted form of aFile)
set aList to paragraphs of aDict
set bRes to ""
set header to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<array>
"
set bDict to ""
set footer to "
</array>
</plist>"
repeat with j in aList
set aCon to (contents of j)
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set aRes to text items of aCon
set AppleScript's text item delimiters to curDelim
set phrase to (item 2 of aRes)
set shortcut to (item 1 of aRes)
if not (phrase = "" and shortcut = "") then
set bDict to " <dict>
<key>phrase</key>
<string>" & phrase & "</string>
<key>shortcut</key>
<string>" & shortcut & "</string>
</dict>
"
set bRes to bRes & bDict
end if
end repeat
if bRes = "" then
beep
delay 0.3
return
end if
set cRes to header & (text 1 thru -2 of bRes) & footer
set uuid to do shell script "uuidgen"
do shell script "cd ~/Desktop;touch " & uuid & ".plist;echo " & (quoted form of cRes) & " > " & uuid & ".plist"
end if
end repeat
end main

on extCheck(aFile)
tell application "Finder"
set anExt to name extension of (aFile as POSIX file as alias)
if anExt = "txt" then
return true
else
return false
end if
end tell
end extCheck

on open dropedFiles
return my main(dropedFiles)
end open

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

更新履歴

inserted by FC2 system