Ubuntu – Change dconf keys without logging into X in Puppet

command linedconfpuppet

Is there a way to set a dconf key by command line, without logging into X?
I'd like to use this from Puppet.

If I try (from SSH, as the normal user) a simple

dconf write /desktop/gnome/remote-access/enabled true

I get

error: Command line `dbus-launch --autolaunch=e4d2b270bd8471627460e57c000007f1 --binary-syntax --close-stderr' exited with non-zero exit status 1:
Autolaunch error: X11 initialization failed.\n

While if I try

DISPLAY=:0 dconf write /desktop/gnome/remote-access/enabled true

I get

error: Command line `dbus-launch --autolaunch=e4d2b270bd8471627460e57c000007f1 --binary-syntax --close-stderr' exited with non-zero exit status 1:
Invalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyAutolaunch error: X11 initialization failed.\n

If I remove $HOME/.Xauthority

error: Command line `dbus-launch --autolaunch=e4d2b270bd8471627460e57c000007f1 --binary-syntax --close-stderr' exited with non-zero exit status 1:
No protocol specified\nNo protocol specified\nAutolaunch error: X11 initialization failed.\n

I'm testing on Xubuntu 12.04

(My question is similar to this one but in that case the user is logged in)

Best Answer

Joril, thanks for providing your solution! I would like to add one comment in case people have the problem that I just did: when you use this type definition to set string values, you need to pass in some extra quotes and escape characters. For instance, I wanted to set my color scheme in gedit, so I tried this:

dconf::key {'/org/gnome/gedit/preferences/editor/scheme':
    value => 'solarized_dark',
}

but it didn't work. What I needed to do was this:

dconf::key {'/org/gnome/gedit/preferences/editor/scheme':
    value => "\\\"solarized_dark\\\"",
}

Maybe someone could do that in a simpler way, or build it into the function you provided? Anyway, it works for me now so I'm leaving it alone.

Note that passing in booleans works fine without that extra nonsense, e.g.:

dconf::key {'/org/gnome/gedit/preferences/editor/auto-indent': 
    value => 'true',  
}

works correctly, and I'm assuming that numerical values can probably be set without extra escape characters as well.