2

Is there a way that I can access and edit dconf-editor values programatically, I mean using python or bash?

I want to develop a simple tool to edit some window management shortcuts. I know there are tools like compiz which provides this already, but need to have something quick and simple to work best with my requirements.

I there some sort of API for dconf-editor? or an API for window management keyboard short cuts in general?

Basically I want to edit Switch Windows shortcuts (Alt + Tab) from bash or some other scripting language, i.e. without using a GUI.

wjandrea
  • 14,504
Bmax
  • 223

1 Answers1

2

For Python, use Gio module. Specifically, here's an example of two functions I use in my own code (feel free to see how they're used within my Launcher List Indicator):

from gi.repository import Gio

Define your own class here

# Note that these use `self` for use with classes
# this could be removed otherwise

def gsettings_get(self, schema, path, key): """Get value of gsettings schema""" if path is None: gsettings = Gio.Settings.new(schema) else: gsettings = Gio.Settings.new_with_path(schema, path) return gsettings.get_value(key)

def gsettings_set(self, schema, path, key, value): """Set value of gsettings schema""" if path is None: gsettings = Gio.Settings.new(schema) else: gsettings = Gio.Settings.new_with_path(schema, path) if isinstance(value, list): return gsettings.set_strv(key, value) if isinstance(value, int): return gsettings.set_int(key, value)

These functions make getting and setting values easy and similar to the command-line utilities; schema, path, and key values are all strings. For instance, to set Unity launcher position to "Bottom" you would do:

self.gsettings_set('com.canonical.Unity.Launcher', 'launcher-position', 'Bottom')

For shell scripts, there are dconf and gsettings command-line tools, the later being a front-end to dconf. The gsettings command is preferred because it performs safety checks on the input values. Example of usage:

gsettings set com.canonical.Unity.Launcher launcher-position 'Bottom'

You can call these two from python using subprocess.call() or subprocess.check_output(), but this has the overhead of spawning extra process, which is unnecessary (And if you're going to do it Pythonic way, do it right via the API).

See also

wjandrea
  • 14,504