Files
yenharvey 96a021edbb fix(macos): 安装时把青简写进系统的第三方输入源表
TISEnableInputSource 不写 com.apple.inputsources 的 AppleEnabledThirdPartyInputSources;
表里没有青简的机器上,「+」列表找不到青简、--register 也切不过去(TISSelectInputSource -50)。
postinstall 以登录用户身份补上 Input Mode 与 Keyboard Input Method 两条,已有青简条目就不动。
macOS 27 上未验证,等 #209 的报告人试。

Refs #209
2026-10-29 12:38:46 +08:00

34 lines
2.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# 装完之后:杀掉旧进程,再以当前登录用户的身份把输入源注册并启用。
# 安装器以 root 运行,而输入源是每个用户自己的设置,所以要切到用户的会话里去调 `qingjian-macos --register`。
set -u
APP="/Library/Input Methods/Qingjian.app"
BIN="$APP/Contents/MacOS/qingjian-macos"
pkill -x qingjian-macos 2>/dev/null || true
user="$(stat -f%Su /dev/console 2>/dev/null || true)"
if [ -n "$user" ] && [ "$user" != "root" ]; then
uid="$(id -u "$user")"
# 删掉这个用户的输入源缓存(共享的一份 + 每个沙盒应用各一份):注册时系统广播后,开着的应用作废内存里的表、
# 找不到磁盘缓存就从输入法目录重建,认得青简;不删的话它们重新载入装之前那份,Control+Space 切到青简时崩溃(#346)
cache="$(sudo -u "$user" getconf DARWIN_USER_CACHE_DIR 2>/dev/null)"
[ -n "$cache" ] && rm -f "$cache"com.apple.IntlDataCache.le* "$cache"*/com.apple.IntlDataCache.le* 2>/dev/null
# TISEnableInputSource 不写这张第三方输入源表;有的机器上表里没有青简,「+」列表里就找不到、也切不过去(#209),
# 注销重新登录后系统才按它重建输入法列表。已有青简的条目就不动,免得重复。
prefs="launchctl asuser $uid sudo -u $user defaults"
if ! $prefs read com.apple.inputsources AppleEnabledThirdPartyInputSources 2>/dev/null | grep -q 'app.qingjian.inputmethod'; then
$prefs write com.apple.inputsources AppleEnabledThirdPartyInputSources -array-add \
'<dict><key>Bundle ID</key><string>app.qingjian.inputmethod</string><key>Input Mode</key><string>app.qingjian.inputmethod.Hans</string><key>InputSourceKind</key><string>Input Mode</string></dict>' \
'<dict><key>Bundle ID</key><string>app.qingjian.inputmethod</string><key>InputSourceKind</key><string>Keyboard Input Method</string></dict>'
fi
if launchctl asuser "$uid" sudo -u "$user" "$BIN" --register; then
echo "青简:已为 $user 注册并启用输入源;输入法菜单里没有「青简」就注销后重新登录(系统在登录时才刷新输入法列表)"
else
echo "青简:自动注册输入源失败,请注销后重新登录;仍没有再到「系统设置 → 键盘 → 输入法 → 编辑… → +」的「简体中文」下添加「青简」"
fi
else
echo "青简:没找到登录用户,跳过自动注册"
fi
exit 0