🌟
🍎 macOSユーザー辞書をazooKeyMacにインポートする
macOS の標準「ユーザー辞書(テキスト置換)」のplistを、azooKeyMac が読み込める形式のplistに変換してインポートする方法です。
🧾 ステップ①:macOSのユーザー辞書を書き出す
まず、ユーザー辞書(テキスト置換)を plist 形式でエクスポートします。辞書の画面から
マウスで選択するかCmd+Aで選択して右クリックすると書き出しのメニューが出ます
🛠 ステップ②:変換用スクリプト(Python)
mac_to_azookey.py
という名前で以下のスクリプトを保存してください:
#!/usr/bin/env python3
import plistlib, json, uuid, subprocess, tempfile, sys
from pathlib import Path
# -------------------------------------------------------------------------
def smart_load_plist(path: Path):
"""plistlib.load を試し、失敗したら plutil で xml1 にして再読込"""
try:
with path.open("rb") as f:
return plistlib.load(f)
except Exception:
tmp = Path(tempfile.mktemp(suffix=".plist"))
res = subprocess.run(
["plutil", "-convert", "xml1", str(path), "-o", str(tmp)],
capture_output=True
)
if res.returncode != 0:
sys.exit("plutil で xml1 変換できませんでした")
with tmp.open("rb") as f:
return plistlib.load(f)
def extract_items(root):
"""ルート構造から「辞書項目の配列」を取り出す"""
# Data ルートなら中身を展開
if isinstance(root, (bytes, bytearray)):
try:
root = plistlib.loads(root)
except Exception:
root = json.loads(root.decode("utf-8"))
if isinstance(root, list):
return root
if isinstance(root, dict):
for k in ("NSUserDictionaryReplacementItems", "items", "entries"):
if isinstance(root.get(k), list):
return root[k]
sys.exit("辞書項目の配列が見つかりません")
# -------------------------------------------------------------------------
if len(sys.argv) < 2:
sys.exit("usage: python3 mac_user_dict_to_azookey.py <ユーザ辞書.plist>")
src = Path(sys.argv[1]).expanduser()
if not src.is_file():
sys.exit(f"file not found: {src}")
root = smart_load_plist(src)
mac_items = extract_items(root)
print("📊 原項目数 :", len(mac_items))
# --- azooKey 形式に整形 ----------------------------------------------------
def w(e): # word
return e.get("phrase") or e.get("word") or e.get("text") or ""
def r(e): # reading
return e.get("shortcut") or e.get("reading") or e.get("yomi") or ""
az_items = {
"items": [
{
"id": str(uuid.uuid4()),
"word": w(e).strip(),
"reading": r(e).strip(),
"hint": ""
}
for e in mac_items
if w(e).strip() and r(e).strip()
]
}
print("✅ 有効項目 :", len(az_items["items"]))
if not az_items["items"]:
sys.exit("有効項目が 0 件でした")
# --- JSON → Data → plist ラップ ------------------------------------------
json_bytes = json.dumps(az_items, ensure_ascii=False).encode("utf-8")
wrapped = {
"dev.ensan.inputmethod.azooKeyMac.preference.user_dictionary_temporal2": json_bytes
}
dst = src.with_name(src.stem + "-azookey.plist")
with dst.open("wb") as f:
plistlib.dump(wrapped, f)
🚀 ステップ③:変換を実行!
python3 mac_to_azookey.py ~/Desktop/UserDictionary.plist
同じ場所に ファイル名-azookey.plist
が出力されます。
📥 ステップ④:azooKeyMacにインポート!
defaults import dev.ensan.inputmethod.azooKeyMac ~/Desktop/ファイル名-azookey.plist
その後、azooKeyMac を再起動すれば辞書が使えるようになります 🎉
Discussion