macOSユーザー辞書をCLIで登録する方法

Mac・iPhoneで便利なユーザー辞書機能じゃ。じゃがな、登録するときにユーザー辞書登録画面を探して、入力するの手間じゃろ?

CursorなどのIDEで、以下のプロンプトをコピペするだけじゃ。「読み」と「変換後」を伝えれば、あとは全部やってくれるぞい。


AIに一発でやらせるプロンプト

以下をコピペしてAIに貼り付けるだけじゃ。「読み」と「変換後」を変えて使うのじゃぞ。

macOSのユーザー辞書に以下を登録して。

読み:おつ
変換後:お疲れ様でしたーーーーーー!!!

手順:
1. PlistBuddyで ~/Library/Preferences/.GlobalPreferences.plist に追加
2. killall cfprefsd で設定反映
3. killall "System Settings" でUI反映
4. defaults read -g NSUserDictionaryReplacementItems で登録確認
5. 結果を報告

コマンド:
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0 dict" ~/Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0:replace string 読み" ~/Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0:with string 変換後" ~/Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0:on integer 1" ~/Library/Preferences/.GlobalPreferences.plist
killall cfprefsd
killall "System Settings" 2>/dev/null

プロンプトの解説

このプロンプトがやっておることじゃ:

  1. PlistBuddy - Macの設定ファイルに直接書き込むツールじゃ。ユーザー辞書データを追加するんじゃよ
  2. killall cfprefsd - 設定を管理するプロセスを再起動じゃ。書き込んだ内容をシステムに反映させるぞい
  3. killall “System Settings” - システム設定アプリを再起動じゃ。画面に反映させるんじゃ
  4. defaults read - 登録できたか確認するぞい

通常の方法(defaults writeやSQLite直接編集)では反映されんのじゃ。この方法だけが確実に動作したぞい。


自分でターミナルからやる場合

ステップ1:登録コマンドを実行

# ここを変更!
READING="おつ"
PHRASE="お疲れ様でしたーーーーーー!!!"
 
# 登録(そのままコピペでOK)
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0 dict" ~/Library/Preferences/.GlobalPreferences.plist 2>/dev/null
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0:replace string ${READING}" ~/Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0:with string ${PHRASE}" ~/Library/Preferences/.GlobalPreferences.plist
/usr/libexec/PlistBuddy -c "Add :NSUserDictionaryReplacementItems:0:on integer 1" ~/Library/Preferences/.GlobalPreferences.plist

ステップ2:設定を反映

killall cfprefsd
killall "System Settings" 2>/dev/null

ステップ3:確認

defaults read -g NSUserDictionaryReplacementItems | grep -A2 "${READING}"

うまくいかないとき

  • システム設定を一度閉じて開き直すのじゃ
  • それでもダメならMac再起動じゃぞい

ぜひ試してみてくれい!


メルマガ詳細はこちらをクリック

ジョセGメルマガ

メルマガ詳細はこちらをクリック


Threadsで最新情報を発信中

今すぐフォローせいッッッ!