Blog / Synchronizing desktop settings between Linux machines

When I do something finicky or repetitive, I try to use the power of computers to automate the boring stuff away.

Synchronizing the desktop theme and font settings from my work computer to the travel laptop was one of such "snack" problems. This article is a summary of my notes. It was written with the MATE desktop environment but should work for GNOME as well.

Dotfile?

For many pieces of software, for example git or SSH, making a particular setting portable across multiple machines is as simple as putting it into a versioned dotfile and synchronizing it to any other computer one might want the settings available on.

It would be nice to use the same approach here, but sadly, all desktop settings are stored in one file, ~/.config/dconf/user. This file is a dconf database, not a lightweight text file that we could conveniently sync across machines - so, to prove the Betteridge's Law right, even this question-like heading can be safely answered with a no.

Dconf to the rescue

Fortunately for us here, here is dconf - a tool we can use to read from and write into the dconf database:

In the next few steps, we'll use this utility to find how to "play back" changes to our GUI settings on other machines.

1. Create a before export of the dconf database

As the first step, we'll export the entire dconf database to a text file.

dconf dump / > before.txt

This will create file before.txt with contents like ...

[org/gnome/cheese]
photo-y-resolution=720
burst-delay=1000
video-y-resolution=720
camera='Integrated Camera'
photo-x-resolution=1280
video-x-resolution=1280

[org/gtk/settings/file-chooser]
sort-column='name'
sidebar-width=155
window-position=(454, 269)

... skipping a bit ...

[org/mate/terminal/profiles/default]
background-color='#FFFFFFFFDDDD'
bold-color='#000000000000'
foreground-color='#000000000000'
visible-name='Default'

[desktop/ibus/general]
preload-engines=['xkb:us::eng']
version='1.5.14'

If you don't really know what those do, don't worry - it doesn't matter!

2. Change desktop settings

As the second step, we'll make our changes in the GUI.

As an example for this article, I've changed my desktop theme under System > Preferences > Look and Feel > Appearance from Menta to Blackbird - but you can change anything else you want.

3. Create an after export

Once we've done our changes, we'll create another dconf export.

dconf dump / > after.txt

4. Find out what has changed

To find out which settings have changed, run the diff command:

diff before.txt after.txt --unified 5

The diff command is a tool for finding differences between files. The --unified 5 argument tells it to include 5 lines of text before and after any change, for context.

The command will output something like ...

--- before.txt  2019-09-11 17:19:15.044000000 -0300
+++ after.txt   2019-09-11 17:19:33.004000000 -0300
@@ -83,11 +83,11 @@
 [org/mate/desktop/peripherals/keyboard]
 numlock-state='off'

 [org/mate/desktop/peripherals/mouse]
 cursor-size=24
-cursor-theme='mate'
+cursor-theme='Adwaita'

 [org/mate/desktop/accessibility/keyboard]
 slowkeys-beep-press=true
 mousekeys-accel-time=1200
 bouncekeys-beep-reject=true
@@ -120,23 +120,23 @@
 antialiasing='rgba'
 dpi=96.0
 hinting='slight'

 [org/mate/desktop/interface]
-icon-theme='menta'
-gtk-theme='Menta'
+icon-theme='Adwaita'
+gtk-theme='Blackbird'

 [org/mate/pluma/plugins/filebrowser/on-load]
 virtual-root=''
 tree-view=false
 root='file:///'

 [org/mate/pluma]
 statusbar-visible=true

 [org/mate/marco/general]
-theme='Menta'
+theme='Blackbird'
 num-workspaces=1

 [org/mate/caja/window-state]
 start-with-sidebar=true
 geometry='800x550+674+496'

The output can be interpreted this way:

  1. The setting cursor-theme in the org/mate/desktop/peripherals/mouse section has changed value from 'mate' to 'Adwaita'
  2. The setting icon-theme under org/mate/desktop/interface has changed from 'menta' to 'Adwaita' as well
  3. The setting gtk-theme, also in org/mate/desktop/interface, went from 'Menta' to 'Blackbird'
  4. And lastly, theme in section org/mate/marco/general has also changed from 'Menta' to 'Blackbird'

It may seem counterintuitive to see four changes when changing the theme took only one mouse click, but it highlights the benefits of tracking the changes this way, especially if we're not too familiar with how GTK themes work.

5. Reproduce the changes as portable commands

Now that we know which settings have changed under the hood, we can write a short script to apply the same changes from the command line:

dconf write /org/mate/desktop/peripherals/mouse/cursor-theme "'Adwaita'"
dconf write /org/mate/desktop/interface/icon-theme "'Adwaita'"
dconf write /org/mate/desktop/interface/gtk-theme "'Blackbird'"
dconf write /org/mate/marco/general "'Blackbird'"

Running these commands on other machines will apply the same settings as the original changes from step #2 did - in our case, change the theme to Blackbird.

(Wondering about the "'single quotes within double quotes'"? Those are not a typo - the command needs to be run with them, otherwise dconf won't interpret the values correctly.)

And this takes us to the end of the article - we've found a way to translate GUI settings to specific settings and values and how to apply those changes from CLI. Next, you can run the commands once or put them in a versioned file to run periodically - the possibilities are endless.

Posted Sept. 12, 2020, updated Sept. 23, 2020