风险提示:批量导入大量的自定义短语可能导致系统崩溃。可参考:https://github.com/studyzy/imewlconverter/issues/141#issuecomment-1012951853
具体操作方法:
1、创建一个replace_rules.txt文件,文件内容是需要批量导入的词库,格式如下。’|’符号前面的是短语,’|’符号后面的是输入码。
自定义短语|zdydy 小猪佩齐|xzpq 小羊苏西|xysx
2、把下面脚本保存为 convert_to_plist.sh
文件,和replace_rules.txt放到相同路径下。
#!/bin/bash # 输入文件 input_file="replace_rules.txt" # 输出文件 output_file="replace_rules.plist" # 检查输入文件是否存在 if [ ! -f "$input_file" ]; then echo "输入文件不存在: $input_file" exit 1 fi # 创建临时文件 temp_file=$(mktemp) # 将输入文件内容转换为 plist 格式 echo '<?xml version="1.0" encoding="UTF-8"?>' > "$temp_file" echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >> "$temp_file" echo '<plist version="1.0"><array>' >> "$temp_file" while IFS='|' read -r phrase shortcut; do echo ' <dict>' >> "$temp_file" echo " <key>phrase</key><string>$phrase</string>" >> "$temp_file" echo " <key>shortcut</key><string>$shortcut</string>" >> "$temp_file" echo ' </dict>' >> "$temp_file" done < "$input_file" echo '</array></plist>' >> "$temp_file" # 将临时文件复制到输出文件 mv "$temp_file" "$output_file" echo "转换完成。输出文件:$output_file"
3、cd到脚本所在路径下,运行下面命令。在当前路径下会生成一个replace_rules.plist文件。
chmod +x convert_to_plist.sh ./convert_to_plist.sh
4、把replace_rules.plist文件拖动到“自定义短语”窗口内即可。
发表回复