Gnome settings, changing global defaults and setting a keyboard shortcut for all users

If you're into reading manuals, then start with "Using GCong" in the "GNOME Desktop System Administration Guide". It has almost all the info that I'm going to describe here. However if you're just interested in how to set up global Gnome defaults (ie. defaults for all users), then read on.

Gnome uses XML files for storing all its configuration data. There're GConf XML files in /etc/gconf (these contain the system-wide settings) and in every user's $HOME/.gconf directory for user-level settings. A lot of Gnome settings can be changed via the GUI. Eg. changing keyboard shortcuts can be done in "System / Preferences / Keyboard Shortcuts" (or the same app can be launched with the gnome-keybinding-properties command). This app writes the keyboard shortcut settings into the user's $HOME/.gconf/desktop/gnome/keybindings/custom*/%gconf.xml files.

The Gnome/Ubuntu default keyboard shortcuts come from a number of locations. However the default shortcuts in the "Custom Shortcuts" section come from the file /var/lib/gconf/defaults/%gconf-tree.xml.

In /etc/gconf there're three GConf repositories where you can set preferences:
  • gconf.xml.defaults: defaults set up by the local administrator.
  • gconf.xml.mandatory: settings forced by the local administrator.
  • gconf.xml.system: this is not actively used anymore (it's only there for backward compatibility with Ubuntu Intrepid)
These GConf sources are described in the file /etc/gconf/gconf-version-number/path, where "gconf-version-number" stands for the version of GConf on the given system. (In Ubuntu Jaunty this is /etc/gconf/2/path.)

You find a lot of good examples on setting various preferences in these repositories in the "Setting General Preferences" page of the manual.

Finally ... to set up a mandatory Ctrl+Shift+Esc shortcut to launch the System Monitor (an app similiar to the "Task Manager" in Windows) for all users, you've to use the following commands:
gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type string --set /desktop/gnome/keybindings/custom100/name "System Monitor"
gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type string --set /desktop/gnome/keybindings/custom100/action gnome-system-monitor
gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type string --set /desktop/gnome/keybindings/custom100/binding "<Shift><Control>Escape"

You might ask yourself what happens when system default keybindings conflict with user keybindings? Eg. if a user set's up a keybinding with the name "custom0" and later the sysadmin sets up a keybinding with the same name in /etc/gconf/gconf.xml.defaults. In this case the system-wide "custom0" keybinding will be active and the user's "custom0" keybinding will "vanish". However the config for keybinding "custom0" will still remain in the user's GConf repository (unavailable to the user through the GUI) and if the system-wide "custom0" is removed, the user's keybinding for that name will become active again.

The "Keyboard Shortcuts" application generates keybindings with smart incremental naming. A new binding will get the lowest unused "custom<n>" name based on already existing system-wide and user-level bindings. Thus if there's only a system-wide binding with the name "custom5", the user's first binding will still be "custom0". But if there's a system-wide binding with the name "custom0", then the user's first binding will be named "custom1".

If a sysadmin introduces a new system-wide keybinding with the name "custom0", then the first (I mean in order of creation date) user-level keybinding (defined previously) for every user will become inaccessible and they'll have to set it up again. To provide a smooth user experience, I suggest that sysadmins use high starting numbers for system-wide keybindings, eg. "custom100", "custom101", etc. seems to be high enough. This way it is very unlikely that new system-wide bindings conflict with previously set up user-level keybindings.

Syndicate content