Created
November 12, 2021 09:57
-
-
Save fujimaki-k/47afb7b480b38eea72123b2481f4f0d3 to your computer and use it in GitHub Desktop.
Convert ATOK user dictionary to macOS plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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