我需要配置多个 Ubuntu 14.04/14.10 桌面。大多数配置我都可以轻松完成,因为它们可以在配置文件中或从命令行进行设置。
但我在设置可用语言和设置切换语言的键盘快捷键时遇到了两个问题。我知道如何从gnome-control-center
设置可用语言
Region & Language > Input Sources > English (US) + German + Italian
设置切换语言的键盘快捷键
Shortcut Settings > Typing > Switch to next source (Super+Escape), Switch to previous source (Shift+Super+Escape)
但我不知道如何从配置文件或命令行进行操作,所以我无法自动配置它。
答案1
按键
您正在寻找的钥匙是:
用于编辑输入源:
org.gnome.desktop.input-sources sources
编辑切换语言的键盘快捷键:
org.gnome.desktop.wm.keybindings switch-input-source
向后切换输入源:
org.gnome.desktop.wm.keybindings switch-input-source-backward
编辑设置的命令
从命令行编辑这三个命令的示例:
要编辑输入源,请按照问题中提到的方式设置输入源:
gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us'), ('xkb', 'it'), ('xkb', 'de')]"
将开关快捷键组合设置为Ctrl+space
gsettings set org.gnome.desktop.wm.keybindings switch-input-source "['<Primary>space']"
设置切换快捷键组合向后切换Shift++Superspace
gsettings set org.gnome.desktop.wm.keybindings switch-input-source-backward "['<Shift><Super>space']"
获取当前设置的命令
gsettings get org.gnome.desktop.input-sources sources
gsettings get org.gnome.desktop.wm.keybindings switch-input-source
gsettings get org.gnome.desktop.wm.keybindings switch-input-source-backward
如何找到这些钥匙
您可以使用以下命令列出所有键来在数据库中搜索关键字:
gsettings list-recursively
它将列出所有现有的密钥,或者(我经常这样做)安装并使用+dconf-editor
简单地找到您的关键字。CtrlF
编辑
根据评论中的要求,我添加了一个小脚本来从命令行遍历输入源:
#!/usr/bin/env python3
import subprocess
import sys
src = sys.argv[1]
key = "org.gnome.desktop.input-sources"
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").strip()
src_list = len(eval(get("gsettings get "+key+" sources")))-1
current = int(get("gsettings get "+key+" current").split()[-1])
if src == "+":
set_new_value = "gsettings set "+key+" current "+(str(current+1) if current < src_list else "0")
elif src == "-":
set_new_value = "gsettings set "+key+" current "+(str(current-1) if current > 0 else str(src_list))
subprocess.Popen(["/bin/bash","-c", set_new_value])
运行它
- 将脚本保存到一个空文件中,如下所示
switch_source.py
通过命令运行:
python3 /path/to/switch_source.py +
转到下一个输入源,然后
python3 /path/to/switch_source.py -
转到上一个