想通了。最好的方法似乎是添加一个 Python 块来使用 JSON 库读取和操作首选项文件。在你做任何事情之前,你需要在首选项文件中了解你的方位。您需要更改哪些相关元素?
如果你去 Chromium GUI 中的 Preferences,你可以看到有两个相关的设置:
1) 语言:
2) 字典(用于拼写检查):
这些可以在 Preferences-file 中通过在终端中漂亮地打印文件(使用pygmentize 改进它)或将漂亮打印的输出保存到文件中找到:
less Preferences | python -m json.tool | pygmentize -g
或
~/.config/chromium/Default$ less Preferences | python -m json.tool >> ~/Documents/output.txt
在文件中搜索语言设置,您会发现两个相关元素:
"intl": {
"accept_languages": "en-US,en,nb,fr-FR,gl,de,gr,pt-PT,es-ES,sv"
},
和
"spellcheck": {
"dictionaries": [
"en-US",
"nb",
"de",
"gr",
"pt-PT",
"es-ES",
"sv"
],
"dictionary": ""
}
在您做任何其他事情之前,最好备份 Preferences 文件...接下来,您可以通过将以下 python 块添加到 bash 脚本来更改语言设置:
python - << EOF
import json
import os
data = json.load(open(os.path.expanduser("~/.config/chromium/Default/Preferences"), 'r'))
data['intl'] = {"accept_languages": "en-US,en,nb,fr-FR,gl,de,pt-PT,es-ES,sv"}
data['spellcheck'] = {"dictionaries":["en-US","nb","de","pt-PT","es-ES","sv"],"dictionary":""}
with open(os.path.expanduser('~/.config/chromium/Default/Preferences'), 'w') as outfile:
json.dump(data, outfile)
EOF
在这种情况下,脚本将从可用语言和拼写检查器中删除希腊语。请注意,要添加语言,您需要知道 Chromium 接受的语言代码。
您可以找到更多关于读写 JSON here 和 here,以及更多关于如何在 bash 脚本中包含 Python 脚本here。