我想通过一个终端命令禁用所有自定义和系统键盘快捷键。我需要使用哪个命令来实现它/
答案1
我在一个简单的节点应用程序中完成了此操作:
import childProcess from 'child_process'
const gnomeKeybindings = [
'activate-window-menu','maximize-horizontally','move-to-side-n','move-to-workspace-8','switch-applications','switch-to-workspace-3','switch-windows-backward',
'always-on-top','maximize-vertically','move-to-side-s','move-to-workspace-9','switch-applications-backward',' switch-to-workspace-4','toggle-above',
'begin-move','minimize','move-to-side-w','move-to-workspace-down','switch-group','switch-to-workspace-5','toggle-fullscreen',
'begin-resize','move-to-center','move-to-workspace-1','move-to-workspace-last','switch-group-backward','switch-to-workspace-6','toggle-maximized',
'close','move-to-corner-ne','move-to-workspace-10','move-to-workspace-left','switch-input-source','switch-to-workspace-7','toggle-on-all-workspaces',
'cycle-group','move-to-corner-nw','move-to-workspace-11','move-to-workspace-right','switch-input-source-backward switch-to-workspace-8','toggle-shaded',
'cycle-group-backward','move-to-corner-se','move-to-workspace-12','move-to-workspace-up','switch-panels','switch-to-workspace-9','unmaximize',
'cycle-panels','move-to-corner-sw','move-to-workspace-2','panel-main-menu','switch-panels-backward','switch-to-workspace-down',
'cycle-panels-backward','move-to-monitor-down','move-to-workspace-3','panel-run-dialog','switch-to-workspace-1','switch-to-workspace-last',
'cycle-windows','move-to-monitor-left','move-to-workspace-4','raise','switch-to-workspace-10','switch-to-workspace-left',
'cycle-windows-backward','move-to-monitor-right','move-to-workspace-5','raise-or-lower','switch-to-workspace-11','switch-to-workspace-right',
'lower','move-to-monitor-up','move-to-workspace-6','set-spew-mark','switch-to-workspace-12','switch-to-workspace-up',
'maximize','move-to-side-e','move-to-workspace-7','show-desktop','switch-to-workspace-2','switch-windows'
]
const gnomeShellKeybindings = ['focus-active-notification','open-application-menu','screenshot','screenshot-window','shift-overview-down',
'shift-overview-up','switch-to-application-1','switch-to-application-2','switch-to-application-3','switch-to-application-4','switch-to-application-5',
'switch-to-application-6','switch-to-application-7','switch-to-application-8','switch-to-application-9','show-screenshot-ui','show-screen-recording-ui',
'toggle-application-view','toggle-message-tray','toggle-overview' ]
const gnomeMutterKeybindings = ['rotate-monitor','switch-monitor','tab-popup-cancel','tab-popup-select','toggle-tiled-left','toggle-tiled-right']
const gnomeDashToDockKeybindings = ['app-ctrl-hotkey-1','app-ctrl-hotkey-10','app-ctrl-hotkey-2','app-ctrl-hotkey-3','app-ctrl-hotkey-4','app-ctrl-hotkey-5',
'app-ctrl-hotkey-6','app-ctrl-hotkey-7','app-ctrl-hotkey-8','app-ctrl-hotkey-9',
'app-hotkey-1','app-hotkey-10','app-hotkey-2','app-hotkey-3','app-hotkey-4','app-hotkey-5','app-hotkey-6','app-hotkey-7','app-hotkey-8','app-hotkey-9',
'app-shift-hotkey-1','app-shift-hotkey-10','app-shift-hotkey-2','app-shift-hotkey-3','app-shift-hotkey-4','app-shift-hotkey-5',
'app-shift-hotkey-6','app-shift-hotkey-7','app-shift-hotkey-8','app-shift-hotkey-9','shortcut']
然后循环禁用所有这些
for (let binding of gnomeKeybindings){
childProcess.execFile('gsettings', ['set' ,'org.gnome.desktop.wm.keybindings', `${binding}`, `['']`])
}
for (let binding of gnomeShellKeybindings){
childProcess.execFile('gsettings', ['set' ,'org.gnome.shell.keybindings', `${binding}`, `['']`])
}
for (let binding of gnomeMutterKeybindings){
childProcess.execFile('gsettings', ['set' ,'org.gnome.mutter.keybindings', `${binding}`, `['']`])
}
for (let binding of gnomeDashToDockKeybindings){ // we could use gsettings reset-recursively org.gnome.shell to reset everything
childProcess.execFile('gsettings', ['set' ,'org.gnome.shell.extensions.dash-to-dock', `${binding}`, `['']`])
}
childProcess.execFile('gsettings', ['set' ,'org.gnome.mutter', `overlay-key`, `''`])
当然你可以用 shellscript 来实现这一点 :-)
答案2
跑步:
for schema in $(gsettings list-schemas | grep -E 'keybindings|media-keys')
do
for key in $(gsettings list-keys $schema)
do
if [[ $(gsettings range $schema $key) == "type as" ]]; then
gsettings set $schema $key "@as []"
fi
done
done
请注意,我的机器上gsettings list-schemas | grep keybindings
显示:
$ gsettings list-schemas | grep -E 'keybindings|media-keys'
org.cinnamon.desktop.keybindings
org.cinnamon.desktop.keybindings.media-keys
org.cinnamon.desktop.keybindings.wm
org.gnome.desktop.wm.keybindings
org.gnome.mutter.keybindings
org.gnome.mutter.wayland.keybindings
org.gnome.settings-daemon.plugins.media-keys
org.gnome.shell.keybindings
如果您不想删除所有这些,那么请创建一个模式数组并对其进行迭代,如下所示:
schemas=( org.gnome.desktop.wm.keybindings org.gnome.shell.keybindings org.gnome.mutter.keybindings )
for schema in "${schemas[@]}"
do
for key in $(gsettings list-keys $schema)
do
if [[ $(gsettings range $schema $key) == "type as" ]]; then
gsettings set $schema $key "@as []"
fi
done
done
要仅取消设置自定义键绑定,命令如下:
gsettings reset org.gnome.settings-daemon.plugins.media-keys custom-keybindings