我可以通过以下方式检索自定义键绑定列表:
gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings
返回类似如下的内容:
['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media keys/custom-keybindings/custom1/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/']
但我想通过名称了解目标键绑定?即shutter
-><primary><shift><alt>a
我想出了一个简单但不方便的方法:
gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-
keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-
keybindings/custom0/ name
// return the name like `shutter`
gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-
keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-
keybindings/custom0/ binding
// return the binding like `<primary><shift><alt>a`
有人知道其他优雅的解决方案吗?
答案1
通过名称查找键绑定的小脚本
使用快捷键运行下面的脚本时,它将输出键绑定姓名作为参数。例如:
$ python3 '/home/jacob/Bureaublad/find_keybinding.py' rename
> '<Primary><Alt>r'
如何设置
- 将以下脚本复制到一个空文件中,并将其另存为
find_keybinding.py
通过命令运行:
python3 '/path/to/find_keybinding.py' <shortcut_name>
解释
信息位于输出中
dconf dump /
在自定义键盘快捷键上,这将输出如下部分:
[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom9]
binding='<Primary><Alt>r'
command='/home/jacob/.local/share/nautilus/scripts/change_name'
name='rename'
正如你所见,我们需要上面两行
name='rename'
...因此脚本输出该行,从binding=
剧本
#!/usr/bin/env python3
import subprocess; import sys
key = "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/"
# read the output from dconf dump /, split into lines
ls = [l for l in subprocess.check_output(["dconf", "dump", key]).decode("utf-8").splitlines()]
# find line corresponding to searched name, print two lines higher
print(ls[ls.index([l for l in ls if "name='"+sys.argv[1] in l][0])-2].replace("binding=", ""))
此外
...您可以创建目录~/bin
(如果它尚不存在)并将脚本保存在那里无延伸, 和使其可执行。注销并重新登录,然后只需:
find_keybinding <name>
会做
答案2
对于自定义键,请尝试:
for i in $(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings | awk -F"'" '{ for (i=2;i<=NF;i+=2) print $i }'); do
echo "$(dconf read ${i}binding) $(dconf read ${i}name)"
done
对于其他键,请通过以下命令进行 grep:
for schema in $(gsettings list-schemas | grep -E 'keybindings|media-keys')
do
gsettings list-recursively $schema
done
查看这了解更多信息。