0

I have to execute this code in python

dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-prev "'Disabled'"

Tried With:

os.system('dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-prev "Disabled" ')

Error:

error: 0-1:unknown keyword

Usage:
  dconf write KEY VALUE 

Write a new value to a key

Arguments:
  KEY         A key path (starting, but not ending with '/')
  VALUE       The value to write (in GVariant format)

Please help me on this issue. thanks :-)

1
  • Have you tried with Disabled in double and single quotes like os.system('dconf write /org/compiz/profiles/unity/plugins/unityshell/alt-tab-prev "'Disabled'" '). – gsxruk Jan 20 '18 at 7:55
5

Editing dconf/gsettings from python

You really shouldn't use os.system() for system calls anymore, it has been deprecated and totally outdated for a long time.

There are different options to edit the dconf database.

Using subprocess

Say I have a dconf path /com/gexperts/Tilix/keybindings/app-shortcuts, I can use:

import subprocess

key = "/com/gexperts/Tilix/keybindings/app-shortcuts"

subprocess.Popen([
    "dconf", "write", key, "'enabled'"
])

Mind the quoting!


In most cases however, you will also be able to use (better)gsettings. Use Gio.Settings if the value also can be set from gsettings.


Using Gio.Settings

from gi.repository import Gio

key = "com.gexperts.Tilix.Keybindings"

settings = Gio.Settings.new(key)
settings.set_string("app-shortcuts", "enabled")

See also https://lazka.github.io/pgi-docs/#Gio-2.0/classes/Settings.html#Gio.Settings and https://people.gnome.org/~gcampagna/docs/Gio-2.0/Gio.Settings.html

About gsettings/dconf

Preferences on modern Ubuntu versions are mostly stored in the dconf database in binary format. These settings can be edited directly by dconf (cli), or dconf-editor (gui). Dconf is low level, and directly editing settings via dconf extremely fast and light-weight.

In general it is however considered better practice to edit settings in the database via gsettings if possible, which is the cli frontend to dconf. The reason is that gsettings has a consistency check, safer to use.

You might find this an interesting read on gsettings: https://developer.gnome.org/gio/stable/GSettings.html

And this one on dconf: https://developer.gnome.org/dconf/unstable/dconf-tool.html

Notes

  • I used another path / key example since I don't run Unity.
3
  • dconf code executed for me but If I execute gsettings code I am getting this error (process:5879): GLib-GIO-ERROR **: Settings schema 'org.compiz.profiles.unity.plugins.unityshell' is not installed Trace/breakpoint trap (core dumped). I just want to know, why gsettings not executed and dconf executed ? schema of gsettings and dconf same or different . Any how i got resolved my problem :-) – Dinesh Jan 20 '18 at 11:46
  • @Dinesh what version of Ubuntu do you have? Just installed 16.04 in a VM, the key does not exist there. Not in dconf as well. – Jacob Vlijm Jan 20 '18 at 13:05
  • update from 14.04 to 16.04. Both seniors working fine . @Jacob thank you for your suggestions and comments – Dinesh Jan 20 '18 at 13:24

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.