Gsettigs and dconf to set hotkey

2019-07-02 02:58发布

问题:

Hello
I need to set a hotkey in ubuntu 12.10, i use

gsettings(dconf)

~$ gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ binding '<Primary><Alt>s'
~$ gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ binding '<Primary><Alt>s'
~$ gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ command 'gnome-terminal'

but when i watch this schema i just see

~$ gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings
~$ @as []

but when i use dconf to see this schema

~$ dconf list /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/
binding
command

what i am doing wrong? Thank you.

回答1:

You forgot to set the value for the parent key: custom-keybindings which is of type @as[]. First check if it's empty with:

gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings

If it's empty: [] , run:

gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/']"

If it's not empty you will have to add the existing values to the above command (values must be surrounded by single quotes and separated by comma + space, like ['val1', 'val2', 'val3']). And then run:

gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/custom2/ binding '<Primary><Alt>s'
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/custom2/ command 'gnome-terminal'