Skip to content

Instantly share code, notes, and snippets.

@fujimaki-k
Created November 12, 2021 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujimaki-k/47afb7b480b38eea72123b2481f4f0d3 to your computer and use it in GitHub Desktop.
Save fujimaki-k/47afb7b480b38eea72123b2481f4f0d3 to your computer and use it in GitHub Desktop.
Convert ATOK user dictionary to macOS plist
#!/usr/bin/env python3
# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
import sys
print('<?xml version="1.0" encoding="UTF-8"?>')
print('<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">')
print('<plist version="1.0">')
print('<array>')
with open(sys.argv[1], "r", encoding="UTF-16") as items:
for line in items:
if not line.strip():
continue
if line.startswith("!!"):
continue
(phrase, shortcut, type) = map(str.strip, line.split("\t"))
print(' <dict>')
print(' <key>phrase</key>')
print(' <string>{0}</string>'.format(phrase))
print(' <key>shortcut</key>')
print(' <string>{0}</string>'.format(shortcut))
print(' </dict>')
print('</array>')
print('</plist>')
# Local variables:
# tab-width: 4
# c-basic-offset: 4
# c-hanging-comment-ender-p: nil
# End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment