The Linux Page

Transform Gnome settings in Command Lines

Adjusting to your preference

When trying to setup the Ubuntu environment automatically by installing a package so it works as expected, I have to use the gsettings command. Only, in most cases, the posts you find online tell you to tweak such and such value and these are wrong about 50% of the time. (Or to be more correct, they changed over time and now those old posts give you the wrong answer each time).

In order to find out what you need to change, one way is to use the GUI to make the changes and compare the settings from before and after. Here are the steps to do exactly that:

1. Open the GUI preferences allowing you to make the changes

The Gnome preferences are numerous and most can't be accessed with the basic Ubuntu settings window. Actually, only a few are accessible.

The are two other tools you can use to tweak the settings:

(a) The Gnome Tweaks; in most cases this one is enough and it's still very easy to use

(b) the dconf tool; this GUI is somewhat similar to the Microsoft Windows Registry editor. Ugly and in many cases you really need to know what you doing. However, many times some extremely useful features are only accessible through this tool.

2. Setup the wrong value

At this stage, you want a value which is not what you want in the end. Probably the default if you can reset that to such, although which value shouldn't matter much as long it is not the one you actually want to have in the end.

P.S. keep the preferences opened, you'll need the window two more times.

3. Extract the settings with the wrong value

Now you are ready for the first settings extraction which goes like this:

gsettings list-recursively > a.txt

You can change the name of the file were you want to save the settings to anything you'd like, of course. Feel free to look at the contents with a text editor or the less (more?!) command.

4. Fix the Preferences

Now that we have a list of the wrong preferences, we can get ready to generate the list of the right preferences.

So go back to the preferences and do the fixes, i.e. set the preferences up the way you like them.

5. Extract the Good Preferences

Now that we have the GUI selection set to the right preferences, extract them again in a different file:

gsettings list-recursively > b.txt

Again, you can check this file with your favorite editor, but most importantly, let's move on to the next step.

6. Compare the Settings Changes

At this time we're ready to see what changed. Type the following:

diff a.txt b.txt

and the flag(s) that were modified by the preferences user interface will appear on your screen.

Here is an example when I was trying to turn off the suspend feature as the computer I'm running with is an embedded system which can never go to that mode:

$ diff a.txt b.txt
1394c1394
< org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'suspend'
---
> org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'

Now we see that the flag that needs to be updated is:

  • Schema: org.gnome.settings-deamon.plugins.power
  • Key: sleep-inactive-ac-type
  • Value: nothing

7. Set Preferences back to the wrong value(s)

Now to test that you can do it in your console, set the value back to what you consider the wrong value using the user interface as before.

Click on another tab and come back, make sure it changed as expected.

8. Set the New Value

From my example above, here is the command one can use to change a Gnome settings value:

gsettings set org.gnome.settings-daemon.plugins.power \
                                sleep-inactive-ac-type 'nothing'

I show the command on two lines to make it simpler to read but it can all be written on a single line.

9. Verify in the Preferences

Finally we can see that the value was changed in the preferences by going to another tab and coming back. This reads the new values from the Gnome settings and shows them.

Some interfaces may change automatically when you run the gsettings command, but that is not the case on Ubuntu 18.04 for the screensaver and suspend features. So it is likely not going to work for you either on that version of Ubuntu.

Assuming you see the change to the right value, you're done. You now have the command to use to forcibly change settings from your console (or a package .postinst script).

Last Note

All the settings I've seen to tweak Gnome worked in this way. I think there are a few others that are not setup in the gsettings (i.e. printer default settings). At this point, you're on your own for those.