Ubuntu – How to read default key value with dconf or gsettings


I would like to know the default value of a dconf/gsettings key.

My question is a followup of the question below:
Where can I get a list of SCHEMA / PATH / KEY to use with gsettings?

What I'm trying to do, so create a script that reads all my personal preferences so I can back them up and restore them. I plan to iterate though all keys, like the script above, see what keys have been changed from their default value, and make a note of these, that can be restored later.

I see that the dconf-editor display the keys' default value, but I'd very much like to script this. Also, I don't see how parsing the schemas /usr/share/glib-2.0/schemas/ can be automated. Maybe someone can help?

gsettings get-default|list-defaults would be nice =)

(Geesh, it was much easier in the old days where you just kept your ~/.somethingrc in subversion … =\

Based on the answer given below, I've updated the script to print schema, key, key's data type, default value, and actual value:


for schema in $(gsettings list-schemas | sort); do
    for key in $(gsettings list-keys $schema | sort); do
        type="$(gsettings range $schema $key | tr "\n" " ")"
        default="$(XDG_CONFIG_HOME=/tmp/ gsettings get $schema $key | tr "\n" " ")"
        value="$(gsettings get $schema $key | tr "\n" " ")"
        echo "$schema :: $key :: $type :: $default :: $value"

This workaround basically covers what I need. I'll continue working on the backup scrip from here.

Best Answer

There does not seem to be a nice way to get at the default values directly, but since the client checks XDG_CONFIG_HOME in the environment a decent workaround to get values from a fresh config might be:

XDG_CONFIG_HOME=/nonexistent gsettings get SCHEMA KEY