19

I like to run a couple of scripts to automatically install packages and do some configurations on fresh OS installs. I use gnome shell with a few extensions and was thinking of improving my scripts to configure them.

I usually configure the extensions using gnome-shell-extension-prefs or dconf-editor and I know how to edit other schemas from the command line. Example:

gsettings set org.gnome.desktop.background picture-options stretched

But, although I can find and edit the installed extensions under org.gnome.shell.extensions using dconf-editor I can't access them using gsettings since they don't seem to have an assigned schema:

No such schema 'org.gnome.shell.extensions.extname'

The only extensions accessible with gsettings seem to be the ones that came pre-installed.

So, the question is, how can I configure the installed extensions from the command line? Is there any way to assign to gsettings the compiled schemas in ~/.local/share/gnome-shell/extensions/ ? Maybe I'm looking in the wrong direction.

Environment: Ubuntu Gnome 14.04 (Gnome Shell 3.10.4)

Thanks in advance.

muru
  • 197,895
  • 55
  • 485
  • 740
albhilazo
  • 449

4 Answers4

15

Found the answer by myself in the end.

sudo cp ~/.local/share/gnome-shell/extensions/extname/schemas/org.gnome.shell.extensions.extname.gschema.xml \
    /usr/share/glib-2.0/schemas/ &&
sudo glib-compile-schemas /usr/share/glib-2.0/schemas/

Copy and compile the schemas in ~/.local/share/gnome-shell/extensions and gsettings will be able to work with them.

albhilazo
  • 449
  • 1
    nice bit of digging! – Pancho Feb 22 '18 at 20:21
  • 1
    Just ran into the same bug. There must be a better solution than copying schemas of extensions that are installed locally to the global directory. Any updates to this issue? – engineer Mar 23 '20 at 22:33
  • I installed the extension globally into /usr/share/gnome-shell/extensions - yet the schemas have to be copied. – queeg Feb 09 '22 at 20:17
  • for security reason and convenience, you should never do this for user specific extensions. This solution simply turn the per user extensions to global extensions with unified settings. not good – Wang Oct 13 '22 at 21:55
  • 1
    @Wang Wrong. This does not "turn user extensions to global extensions with unified settings". It simply installs the extension and schema system-wide so that every user has access to them. Every user still has individual dconf databases with per-user settings for every extension! And there are no security issues either! This is exactly how extensions are pre-installed by distributions. – Mitch McMabers May 20 '23 at 16:57
11

In CentOS 7 - and I would think in Ubuntu also - I've identified what I think is a slight improvement on the accepted answer by introducing the --schemadir switch as follows:

# gsettings --schemadir ${schemaDir} set ${schema} ${key} "${value}"

In the above command gsettings directly sets ${key} to ${value} in ${schema} where ${schema} does not reside in the default /usr/share/glib-2.0/schemas directory. (and there is no requirement to move the schema to the default directory)

Some examples:

gsettings --schemadir ~/.local/share/gnome-shell/extensions/putWindow@clemens.lab21.org/schemas/ list-recursively org.gnome.shell.extensions.org-lab21-putwindow
gsettings --schemadir ~/.local/share/gnome-shell/extensions/unitylike-hotkey@webgyerek.net/schemas/  list-recursively org.gnome.shell.extensions.app-keys
gsettings --schemadir ~/.local/share/gnome-shell/extensions/emoji-selector@maestroschan.fr/schemas/  list-recursively org.gnome.shell.extensions.emoji-selector
abu_bua
  • 10,783
Pancho
  • 211
  • 1
    onfirmed working on Ubuntu 18.04, GS 3.28. As an example: gsettings --schemadir ~/.local/share/gnome-shell/extensions/putWindow@clemens.lab21.org/schemas/ list-recursively org.gnome.shell.extensions.org-lab21-putwindow – eddygeek Sep 19 '18 at 11:06
  • Works on Ubuntu 20.04 as well gsettings --schemadir ~/.local/share/gnome-shell/extensions/user-theme@gnome-shell-extensions.gcampax.github.com/schemas set org.gnome.shell.extensions.user-theme name "Arc" – Alex Burdusel Dec 30 '20 at 09:12
  • setting just schemadir revealed an error message that the extension (which was detected) is not installed properly - Ubuntu 20 LTS – queeg Feb 09 '22 at 20:18
1

I've written this script: Bash script to enable/disable gnome-shell-extensions and more.

Just cp it in /usr/bin or /usr/local/bin and make it executable:

sudo chmod +x /usr/bin/gnome-shell-extension-cl

Check the help.

Enable extension:

gnome-shell-extension-cl -e extension-name

Disable extension:

gnome-shell-extension-cl -d extension-name
karel
  • 114,770
  • Would be good if the script had a toggle option. That is, enable is extension is disabled and disable if it is enabled. – To Do May 30 '20 at 14:38
0

dconf Documentation Says:

The dconf API is not particularly friendly, and is not guaranteed to be stable. Because of this and the lack of portability, you almost certainly want to use some sort of wrapper API around it. The wrapper API used by GTK+ and GNOME applications is GSettings2, which is included as part of GLib.

Here, dconf-editor is Graphical editor for gsettings and dconf.

dconf-editor Documentation Says:

dconf-editor reads gsettings schemas from $XDG_DATA_DIRS/glib-2.0/schemas to obtain descriptions, default values and allowed values for keys.

credits to @albhilazo and How to properly configure a dconf schema from a gschema.xml file?:

find $HOME/.local/share/gnome-shell/extensions/ -name '*.gschema.xml' -exec cp "{}" "$HOME/.local/share/glib-2.0/schemas" \;
glib-compile-schemas $HOME/.local/share/glib-2.0/schemas/

glib-compile-schemas Documentation Says:

At runtime, GSettings looks for schemas in the glib-2.0/schemas subdirectories of all directories specified in the XDG_DATA_DIRS environment variable. The usual location to install schema files is /usr/share/glib-2.0/schemas.

If you have not noticed, another way is to use XDG_DATA_DIRS. I have a hunch (not tested it) that, just setting the following in .profile or .zshenv (based on what default shell you are using) will also solve the problem.

export XDG_CACHE_HOME=$HOME/.cache
export XDG_CONFIG_DIRS=/etc/xdg
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_DIRS=/usr/local/share/:/usr/share/
export XDG_DATA_HOME=$HOME/.local/share
export XDG_STATE_HOME=$HOME/.cache