Gsettings does not work from inside a script

Installed kernel: 6.7.6-200.fc39.x86_64
Fedora release 39
Desktop: GNOME 45.4
Display Server: wayland

Followings works as expected (when executed from terminal) and color scheme changes:

$ gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
$ gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'

Followings does not works (i.e. nothing happens) (when executed from inside a bash script) and color scheme does not change:

$ cat Theme.sh
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
gsettings get org.gnome.desktop.interface color-scheme
bash ./Theme.sh
'prefer-dark'
gsettings get org.gnome.desktop.interface color-scheme
'prefer-light'

You could try using back ticks for the external command so …

`gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'`

As example for dark theme setting.
You could also make two aliases one “dark-mode” and another “light-mode” that run the appropriate command from the terminal.

You want me to add backticks inside the bash script? Why does the bash script does not work?

This normally works.
Something must be wrong in your case.
Check the output:

id
echo ${DBUS_SESSION_BUS_ADDRESS}
ls -a -l ~/.config/dconf
cat -A Theme.sh
$ id
echo ${DBUS_SESSION_BUS_ADDRESS}
ls -a -l ~/.config/dconf
\cat -A Theme.sh
uid=1000(lamy) gid=1000(lamy) groups=1000(lamy),10(wheel),975(docker) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
unix:path=/run/user/1000/bus
lrwxrwxrwx. 1 lamy 23 May 13  2023 /home/lamy/.config/dconf -> /mnt/Data/.config/dconf/
#!/usr/bin/env bash$
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'$
gsettings get org.gnome.desktop.interface color-scheme$

I’m guessing the problem is related to the the fact that your dconf is stored on a separate partition which breaks interaction with dbus possibly due to incorrect target file ownership or insufficient permissions.

Permission and ownership can be seen as below

$ \ls -la ${HOME}/.config/dconf
lrwxrwxrwx. 1 lamy lamy 23 May 13  2023 /home/lamy/.config/dconf -> /mnt/Data/.config/dconf

$ \ls -la /mnt/Data/.config/dconf
total 80
drwxr-xr-x.   2 lamy lamy  4096 Mar 26 13:15 .
drwxr-xr-x. 126 lamy lamy  4096 Mar 26 01:16 ..
-rw-r--r--.   1 lamy lamy 73459 Mar 26 13:15 user

What should I do?

Try different ways to isolate the issue:

  • Return the dconf to its default location in your home directory.
  • Create a test user with default profile settings.

If the issue persists, it might be related to the method used to invoke the script.