在哪里可以获得与 gsettings 一起使用的 SCHEMA / PATH / KEY 列表?

在哪里可以获得与 gsettings 一起使用的 SCHEMA / PATH / KEY 列表?

经过一番研究,我发现我可以使用gsettings终端中的命令快速设置配置选项,而不是安装dconf-editorgconf-editorCCSM。

但我们需要 SCHEMA/PATH 和 KEY 来设置值。
语法是:

gsettings set SCHEMA[:PATH] KEY VALUE

例如永不自动隐藏启动器:

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

并且,为了使窗口不与启动器重叠:

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

那么,我可以在哪里获得可以使用 gsettings 设置的所有 SCHEMA / PATH / KEY 的列表?

不,请不要建议该gsettings list-keys命令,因为我不知道可能有数百种可用的模式。

答案1

gsettings list-schemas获取所有架构。您也可以使用gsettings list-recursively您想要的,但此程序将列出所有架构的所有键的所有值:(
以免调用脚本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

扩展你的gsettings-iterate-all | grep com.canonical.Unity2d.Launcher 例子

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 

您可以将输出重新路由到文件以便于阅读。

也献给那些富有创造力的人们。以下是 gsettings 的可能选项列表,可能有助于创建其他脚本

答案2

有点晚了,但我才刚刚开始努力解决这个隐私问题......

它看上去就像com.canonical.Unity.Lenses remote-content-search 'none'是您所寻找的切换按钮。

答案3

我一直在使用这个答案多年来,现在我抽出一些时间来改进它,为每个键创建一个 JSON 对象(实际输出是一个对象数组)。它是主观的,可以改进(我愿意接受建议),但它适用于我系统上的架构、键和值。我还添加了每个键的默认值(基于这个答案)。它还支持gsettings在 Flatpak 应用程序容器中运行(但请注意,它的速度要慢得多)并使用 GNU 可以理解的搜索字符串过滤模式grep(无需任何grep选项)。

示例对象

[
  {
    "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"
  }
]

函数定义

# 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/'/\"/g")"
      default_value="$(XDG_CONFIG_HOME=/nonexistent $cmd get "$schema" "$key" | sed "s/'/\"/g")"

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

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

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

            # shellcheck disable=SC2001  # See if you can use ${variable//search/replace} instead
            default_value="$(sed 's/^@[^ ]\+ //' <<< "$default_value")"
          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$' <<< "$data_type"; then
            current_value="\"$current_value\""
            default_value="\"$default_value\""
          # 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]$' <<< "$data_type"; then
            current_value="${current_value//* /}"
            default_value="${default_value//* /}"
          # Replace `nothing` of `mb` (optional boolean) type with `null`
          elif grep -q '^mb$' <<< "$data_type" && grep -q '^nothing$' <<< "$current_value"; then
            current_value='null'
          fi

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

          data+="\"dataType\": \"$data_type\", \"currentValue\": $([ "$data_type" = 'as' ] && echo "$current_value" || sed -z "s/\"/\\\\\"/g;s/\(^\\\\\"\|\\\\\"\n*$\)/\"/g" <<< "$current_value"), \"defaultValue\": $([ "$data_type" = 'as' ] && echo "$default_value" || sed -z "s/\"/\\\\\"/g;s/\(^\\\\\"\|\\\\\"\n*$\)/\"/g" <<< "$default_value")}"
        ;;
      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"
}

使用示例

# 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

数据类型列表

仅供参考,以下是 中可以使用的所有类型的列表(备忘单)gsettings。有关更多信息,请参阅文档

(...) = 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

未来可能的改进

有待改进的地方:

  • 使用getopt;
  • 转换dataType为更有意义的值(例如bboolean;参见上面的数据类型列表);
  • 使排序成为可选的;
  • 优化功能,使其运行更快(可能通过利用gsettings list-recursively)。

相关内容