11

I like to be able to configure things from the command line, so that when I reinstall the OS I can just run a script and get my preferred configuration back.

Since "upgrading" to Ubuntu 17.10, I found I had to use gnome-tweak-tool to get some settings the way I want them.

Once I find a setting in the gnome-tweak-tool GUI, how can I figure out its scriptable translation?

For example the following gsettings lines match the relevant entries in the gnome-tweak-tool screen shot below...

gsettings set org.gnome.desktop.wm.preferences titlebar-font "Tahoma Bold 8"
gsettings set org.gnome.desktop.interface font-name "Tahoma 8"
gsettings set org.gnome.desktop.interface document-font-name "Tahoma 8"
gsettings set org.gnome.desktop.interface monospace-font-name "FixedSC 10"

screen shot from gnome-tweak-tool ...but how could anyone guess that? And how would I, for example, figure out where to get the corresponding settings for hinting and antialiasing?

16

Easily find out what is being set

Instead of searching through a whole directory of options:

  1. Open a terminal window
  2. Run the command:

    dconf watch /
    
  3. Make your changes and see what the terminal shows:

    enter image description here

    ...and there you are.

Dconf & gsettings

In the example, you see the output from dconf. Gsettings is the cli- frontend to dconf. Many times, you can use both a dconf command or a gsettings command. In this case either:

dconf write /org/gnome/desktop/background/show-desktop-icons false

or:

gsettings set org.gnome.desktop.background show-desktop-icons false

If the gsettings key exists however, the latter is considered to be better practice, to protect the integrity of your dconf database.

See also here and here.

  • This is brilliant, thank you. Small questions: (1) how do I know "if the gsettings key exists"? (2) What is the point of two command line interfaces that are for all intents and purposes identical to the user? (3) what's the difference between the first and the third of your "here"? They look like the same page to me. – st01 Nov 3 '17 at 10:43
  • @st01 For (1) you could either sinply run the gsettings command, see if it does the job, or check in dconf editor (not installed by default, but a great tool) if the gsettings key (also) exists. (2) gsettings is the cli frontend to edit the dconf database. Gsettings also checks the integrity of the database, and is therefore preferable to directly editing the dconf database. Since gsettings is higher level, it is slower though. (3), Ah, that is silly :), you are right. Will edit – Jacob Vlijm Nov 3 '17 at 12:23
  • @JacobVlijm thanks very much! You saved my life!! – Marslo May 29 '18 at 8:43
7

For most of the settings you can use this approach:

  • Export the list of gsettings into a temporary file:

    gsettings list-recursively > /tmp/gsettings.before
    
  • Make your changes by gnome-tweak-tool (or unity-control-center);

  • Export the list of gsettings into an another temporary file:

    gsettings list-recursively > /tmp/gsettings.after
    
  • Compare the two files (.before and .after) and get the differences:

    diff /tmp/gsettings.before /tmp/gsettings.after | grep '[>|<]'
    

    Or compare and get only the new values (source):

    diff /tmp/gsettings.before /tmp/gsettings.after | grep -Po '> \K.*'
    

    Or compare and get only the new values, but replace the beginning of the lines with gsettings set to prepare a list of commands, that cold be stored directly within your script file (source):

    diff /tmp/gsettings.before /tmp/gsettings.after | sed 's/>/gsettings set/;tx;d;:x'
    

You can run all these commands from one line (or you can create a script to automate the process):

gsettings list-recursively > /tmp/gsettings.before; gnome-tweak-tool; gsettings list-recursively > /tmp/gsettings.after; diff /tmp/gsettings.before /tmp/gsettings.after | grep '[>|<]'

The next demo is created within Ubuntu 16.04. I think the approach shall work also within 17.10:

enter image description here


Update: I just found an easy way within Ubuntu 17.10:

enter image description here

  • 1
    Very useful, thank you, I didn't know you could dump all settings like this. – st01 Nov 3 '17 at 10:44
  • 1
    This is superb, thank you so much! Now I can restore my old config when I mess around in gsettings. – Nicholas Stommel Nov 11 '17 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.