How can I script the settings made by gnome-tweak-tool?

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.


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