8

Is there an easy way to do array manipulation in gsettings? I am comparing gsettings to OS X's defaults command that offers the defaults domain --array key overwrite-value and defaults domain --array-add key added-value interface for manipulating arrays.

As far as I can tell there is only gsettings set domain key "['overwrite-value']" available to gsettings. Not really pretty for when you want to add or remove one entry from an array.

I have seen a suggestion that allow me to add to an array, but I would rather use a interface if there is one.

Daniel
  • 1,288

2 Answers2

4

No, gsettings doesn't support any array operations except getting and setting the whole array.

0

I created a tool called gsettings-array to manipulate GSettings arrays. It provides a variety of operations such as insert, list, sort, deduplicate, pop, remove, and clear.

You can download and make the script executable using the following commands:

wget https://gist.github.com/rindeal/c5786254410028f760ee2351d884a744/raw/gsettings-array.py
chmod +x gsettings-array.py

The tool requires Python 3 and the python3-gi package, which provides Python 3 bindings for the Glib library.

The general usage of gsettings-array remains the same as gsettings.

For example to insert a tuple of two strings at the beginning of an array and ensure no duplicates.

gsettings-array insert --dedup \
    "org.gnome.desktop.input-sources" "sources" 0 \
    "('xkb', 'us+cz_sk_de')"

For more information and examples of how to use the various commands, please visit the project homepage.

rindeal
  • 105