How to read default key value with dconf or gsettings?

5,233

Solution 1

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

Solution 2

If you are interested in backing up and restore your settings (in this case you should change the title of your question).

Backup

You can backup your settings with

gsettings list-recursively > backup

This writes all keys to the file backup in you Home-Folder.

Restore

As far as I know there isn't any direct option to import the file back to dconf. Maybe you could write a routine that reads the backup file line by line and executes gsettings set <input line from backup> to restore your settings.

Share:
5,233

Related videos on Youtube

Zta
Author by

Zta

Updated on September 18, 2022

Comments

  • Zta
    Zta over 1 year

    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:

    #!/bin/bash
    
    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"
        done
    done
    

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

    • Andreas Storvik Strauman
      Andreas Storvik Strauman over 4 years
      If anyone else also got here looking for how to reset a key to its default value, then gsettings reset KEY is the way to go.
  • Benjamin R
    Benjamin R over 2 years
    For anyone wondering, you can use the same approach with dconf as well e.g. XDG_CONFIG_HOME=/nonexistent dconf read /path/to/key