39

After doing some research, I found that I can quickly set configuration options using the gsettings command in the terminal, instead of installing dconf-editor or gconf-editor or CCSM.

But we need the SCHEMA/PATH and KEY to set the value.
Syntax is:

gsettings set SCHEMA[:PATH] KEY VALUE

For example to never auto-hide the launcher:

gsettings set com.canonical.Unity2d.Launcher hide-mode 0

And, for windows not to overlap the launcher:

gsettings set com.canonical.Unity2d.Launcher use-strut true 

So, where can I get a list of all the SCHEMA / PATH / KEY that can be set with gsettings?

No, please don't suggest the gsettings list-keys command, because I don't know the possibly hundreds of schema available.

dessert
  • 40,956
Sri
  • 1,743

2 Answers2

53

gsettings list-schemas gets you all the schema. You can also use gsettings list-recursively for what you want but this program will list all the values for all the keys for all schemas:
(Lest's call the script gsettings-iterate-all)

#!/bin/bash
# Gnome 3 can be customised from the command line via the gsettings command
# This script should help you to find what you're looking for by
# listing the ranges for all keys for each schema

for schema in $(gsettings list-schemas | sort)
do
    for key in $(gsettings list-keys $schema | sort)
    do
        value="$(gsettings range $schema $key | tr "\n" " ")"
        echo "$schema :: $key :: $value"
    done
done

Expanding on your example gsettings-iterate-all | grep com.canonical.Unity2d.Launcher yields

com.canonical.Unity2d.Launcher :: edge-decayrate :: type i 
com.canonical.Unity2d.Launcher :: edge-overcome-pressure :: type i 
com.canonical.Unity2d.Launcher :: edge-responsiveness :: type d 
com.canonical.Unity2d.Launcher :: edge-reveal-pressure :: type i 
com.canonical.Unity2d.Launcher :: edge-stop-velocity :: type i 
com.canonical.Unity2d.Launcher :: hide-mode :: type i 
com.canonical.Unity2d.Launcher :: only-one-launcher :: type b 
com.canonical.Unity2d.Launcher :: reveal-mode :: type i 
com.canonical.Unity2d.Launcher :: super-key-enable :: type b 

You can reroute the output to a file for easy reading.

And for creative folks out there. Here is a list of possible options to gsettings that might help create other scripts.

Volker Siegel
  • 13,295
Rinzwind
  • 309,379
2

I’ve been using the code from this answer for years, now I’ve found some time to improve it by creating a JSON object per key (the actual output is an array of objects). It is opinionated and it could be improved (I am open to suggestions), however, it works for the schemas, keys and values I have on my system. I have also added the default value of each key (based on this SO answer). It also supports running gsettings in containers of Flatpak apps (although be warned that it is much slower) and filtering schemas using a search string that is understood by GNU grep (without any grep options).

Example objects

[
  {
    "currentValue": false,
    "dataType": "b",
    "defaultValue": false,
    "key": "symbolic-status-icons",
    "schema": "org.blueman.general",
    "type": "type"
  },
    {
    "currentValue": 60,
    "dataType": "i",
    "defaultValue": 60,
    "key": "time",
    "schema": "org.blueman.plugins.discvmanager",
    "type": "type"
  },
    {
    "currentValue": "[{\"adapter\": \"64:79:F0:BE:E9:51\", \"address\": \"C0:DC:DA:14:F7:FB\", \"alias\": \"note10\", \"icon\": \"phone\", \"name\": \"Audio a
nd input profiles\", \"uuid\": \"00000000-0000-0000-0000-000000000000\", \"time\": \"1702752276.9439752\"}]",
    "dataType": "aa{ss}",
    "defaultValue": "@aa{ss} []",
    "key": "recent-connections",
    "schema": "org.blueman.plugins.recentconns",
    "type": "type"
  },
  {
    "currentValue": 2.3999999999999999,
    "dataType": "d",
    "defaultValue": 2.3999999999999999,
    "key": "display-gamma",
    "schema": "org.freedesktop.ColorHelper",
    "type": "type"
  },
  {
    "currentValue": -1,
    "dataType": "i",
    "defaultValue": -1,
    "key": "crawling-interval",
    "max": 365,
    "min": -2,
    "schema": "org.freedesktop.Tracker3.Miner.Files",
    "type": "range"
  },
  {
    "currentValue": "last",
    "defaultValue": "last",
    "enumList": [
      "last",
      "next"
    ],
    "key": "new-tab-position",
    "schema": "org.gnome.Terminal.Legacy.Settings",
    "type": "enum"
  },
  {
    "currentValue": 0.66000000000000003,
    "dataType": "d",
    "defaultValue": 0.66000000000000003,
    "key": "cross-hairs-opacity",
    "max": 1.0,
    "min": 0.0,
    "schema": "org.gnome.desktop.a11y.magnifier",
    "type": "range"
  },
  {
    "currentValue": 500,
    "dataType": "u",
    "defaultValue": 500,
    "key": "delay",
    "schema": "org.gnome.desktop.peripherals.keyboard",
    "type": "type"
  }
]

Function definition

# Dependendies:
# - Bash;
# - GNU `grep`;
# - GNU `sed`;
# - `gsettings`;
# - `jq`;
# - (optional) `flatpak`.

gsls() {

Variables

Note: Use search_string to limit the schemas. It could be any regex string that GNU grep understands without any option provided.

Note: Use empty string to search for any schema in a Flatpak app, however, note that running gsettings in a Flatpak app (container) takes much longer than doing it directly on the host.

Note: app must be a valid Flatpak app ID.

local search_string="$1" local app="$2" local data='' local cmd key schema

if [ -z "$app" ]; then cmd='gsettings' else if ! command -v flatpak &> /dev/null; then # shellcheck disable=SC2016 # Expressions don't expand in single quotes, use double quotes for that echo 'ERROR: flatpak cannot be found in PATH.' return fi

cmd="flatpak run --command=gsettings $app"

fi

Cycle through matching schemas

for schema in $($cmd list-schemas | grep "$([ -n "$search_string" ] && echo "$search_string" || echo '.*')"); do # Cycle through all keys of matching schemas for key in $($cmd list-keys "$schema"); do local current_value default_value type type_string type_string="$($cmd range "$schema" $key | tr "\n" " ")" type="$(grep -Po '^[^ ]+' <<< "$type_string")" current_value="$($cmd get "$schema" "$key" | sed "s/'/&quot;/g")" default_value="$(XDG_CONFIG_HOME=/nonexistent $cmd get "$schema" "$key" | sed "s/'/&quot;/g")"

  # Add those object properties to `data` which are the same for any `type`
  data+=&quot;{\&quot;schema\&quot;: \&quot;$schema\&quot;, \&quot;key\&quot;: \&quot;$key\&quot;, \&quot;type\&quot;: \&quot;$type\&quot;, &quot;

  case &quot;$type&quot; in
    'enum')
      data+=&quot;\&quot;enumList\&quot;: [$(sed &quot;s/^enum \(.*\) $/\1/;s/ /, /g;s/'/\&quot;/g&quot; &lt;&lt;&lt; &quot;$type_string&quot;)], \&quot;currentValue\&quot;: $current_value, \&quot;defaultValue\&quot;: $default_value}&quot;
    ;;
    'range')
      data+=&quot;\&quot;dataType\&quot;: \&quot;$(grep -Po &quot;^$type \K[^ ]+&quot; &lt;&lt;&lt; &quot;$type_string&quot;)\&quot;, \&quot;min\&quot;: $(grep -Po &quot;^$type [^ ]+ \K[^ ]+&quot; &lt;&lt;&lt; &quot;$type_string&quot;), \&quot;max\&quot;: $(grep -Po &quot;^$type [^ ]+ [^ ]+ \K[^ ]+&quot; &lt;&lt;&lt; &quot;$type_string&quot;), \&quot;currentValue\&quot;: $current_value, \&quot;defaultValue\&quot;: $default_value}&quot;
    ;;
    'type')
      local data_type
      data_type=&quot;$(grep -Po &quot;^$type \K[^ ]+&quot; &lt;&lt;&lt; &quot;$type_string&quot;)&quot;

      if grep -q '^@' &lt;&lt;&lt; &quot;$current_value&quot;; then
        # shellcheck disable=SC2001  # See if you can use ${variable//search/replace} instead
        current_value=&quot;$(sed 's/^@[^ ]\+ //' &lt;&lt;&lt; &quot;$current_value&quot;)&quot;

        # shellcheck disable=SC2001  # See if you can use ${variable//search/replace} instead
        default_value=&quot;$(sed 's/^@[^ ]\+ //' &lt;&lt;&lt; &quot;$default_value&quot;)&quot;
      fi

      # Add double quotes when the value is not a boolean or a number or an array of a basic type or an optional boolean
      if ! grep -q '^[bdhinqstux]$\|^a[a-z]*$\|^mb$' &lt;&lt;&lt; &quot;$data_type&quot;; then
        current_value=&quot;\&quot;$current_value\&quot;&quot;
        default_value=&quot;\&quot;$default_value\&quot;&quot;
      # Remove everything up to rightmost space of number types
      # Note: This is required because values of some types are prepended by their types (e.g. `uint32 3`).
      elif grep -q '^[nqtux]$' &lt;&lt;&lt; &quot;$data_type&quot;; then
        current_value=&quot;${current_value//* /}&quot;
        default_value=&quot;${default_value//* /}&quot;
      # Replace `nothing` of `mb` (optional boolean) type with `null`
      elif grep -q '^mb$' &lt;&lt;&lt; &quot;$data_type&quot; &amp;&amp; grep -q '^nothing$' &lt;&lt;&lt; &quot;$current_value&quot;; then
        current_value='null'
      fi

      # Replace `nothing` of `mb` (optional boolean) type with `null`
      if grep -q '^mb$' &lt;&lt;&lt; &quot;$data_type&quot; &amp;&amp; grep -q '^nothing$' &lt;&lt;&lt; &quot;$default_value&quot;; then
        default_value='null'
      fi

      data+=&quot;\&quot;dataType\&quot;: \&quot;$data_type\&quot;, \&quot;currentValue\&quot;: $([ &quot;$data_type&quot; = 'as' ] &amp;&amp; echo &quot;$current_value&quot; || sed -z &quot;s/\&quot;/\\\\\&quot;/g;s/\(^\\\\\&quot;\|\\\\\&quot;\n*$\)/\&quot;/g&quot; &lt;&lt;&lt; &quot;$current_value&quot;), \&quot;defaultValue\&quot;: $([ &quot;$data_type&quot; = 'as' ] &amp;&amp; echo &quot;$default_value&quot; || sed -z &quot;s/\&quot;/\\\\\&quot;/g;s/\(^\\\\\&quot;\|\\\\\&quot;\n*$\)/\&quot;/g&quot; &lt;&lt;&lt; &quot;$default_value&quot;)}&quot;
    ;;
  esac
done

done

Output a JSON string (array of objects)

Note: The -S option sorts the keys alphabetically.

Note: The -s option is required, as jq is used to merge individual JSON strings (documents) into an array.

Note: sort_by(.key) | sort_by(.schema) sorts the objects in the array first by schema, then by key.

jq -Ss 'sort_by(.key) | sort_by(.schema)' <<< "$data" }

Usage examples

# Get all keys of all schemas
# Note: It takes about 16-18 seconds to complete on my computer (the length of the returned array is 679).
gsls | less

Get all keys from schemas matching terminal

gsls terminal | less

Get all keys from schemas matching Prompt in the Flatpak app org.gnome.Prompt.Devel (GNOME Prompt)

Note: It takes about 11-12 seconds to complete on my computer (the length of the returned array is 49).

gsls Prompt org.gnome.Prompt.Devel | less

List of data types

FYI, here is a list (cheatsheet) of all types that could be used in gsettings. For more information, see the docs.

(...) = tuple
* = any
? = basic
a = array
b = boolean
d = double
g = signature
h = int32_file_desc
i = int32
m = maybe/nullable/optional
n = int16
o = object_path
q = uint16
r = indefinite_tuple
s = string
t = uint64
u = uint32
v = variant
x = int64
y = byte
{...} = dictionary_entry/object

Possible future improvements

Some stuff to improve:

  • use getopt;
  • convert dataType to a more meaningful value (e.g. bboolean; see the data type list above);
  • make the sorting optional;
  • optimise the function so that it runs faster (possibly by utilising gsettings list-recursively).