2

In my ~/.bashrc

Terminal() {
    TerminalDarkProfile="b1dcc9dd-5262-4d8d-a863-c897e6d979b9"
    TerminalLightProfile="3dd28c15-6ba4-4ba0-8289-ab023e6c88fc"

    Gsetting="org.gnome.Terminal.ProfilesList"
    [[ "${1}" == 'Light' ]] && gsettings set "${Gsetting}" default "${TerminalLightProfile}"
    [[ "${1}" == 'Dark' ]] && gsettings set "${Gsetting}" default "${TerminalDarkProfile}"
    gsettings get "${Gsetting}" default
}

If I type Terminal Light in bash terminal, there is no output and the Gnome terminal colour won't change.

But if I paste the function in the terminal manually:

$ Terminal() {
    TerminalDarkProfile="b1dcc9dd-5262-4d8d-a863-c897e6d979b9"
    TerminalLightProfile="3dd28c15-6ba4-4ba0-8289-ab023e6c88fc"

    Gsetting="org.gnome.Terminal.ProfilesList"
    [[ "${1}" == 'Light' ]] && gsettings set "${Gsetting}" default "${TerminalLightProfile}"
    [[ "${1}" == 'Dark' ]] && gsettings set "${Gsetting}" default "${TerminalDarkProfile}"
    gsettings get "${Gsetting}" default
}
$ Terminal Light
'3dd28c15-6ba4-4ba0-8289-ab023e6c88fc'

Then, we can see that gsettings are working, and indeed the gnome terminal profile changes!

Issue

Why is this happening? How can I change gsettings from inside a script or bashfunction defined in ~/.bashrc


Edit

$ type Terminal
bash: type Terminal: command not found
$ Terminal Dark

I am surprised that type Terminal: command not found but Terminal Dark gives no output!

Additionally:

cat Theme.sh
#!/usr/bin/env bash
set -xv
echo $DBUS_SESSION_BUS_ADDRESS
whoami
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
gsettings get org.gnome.desktop.interface color-scheme
$ bash ./Theme.sh 
echo $DBUS_SESSION_BUS_ADDRESS
+ echo unix:path=/run/user/1000/bus
unix:path=/run/user/1000/bus
whoami
+ whoami
lamy
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
+ gsettings set org.gnome.desktop.interface color-scheme prefer-light
gsettings get org.gnome.desktop.interface color-scheme
+ gsettings get org.gnome.desktop.interface color-scheme
'prefer-light'
$ gsettings get org.gnome.desktop.interface color-scheme
'prefer-dark'

We can see that gsettings get immediately shows different value right after running the script!

7
  • @G-ManSays'ReinstateMonica' Please see Edit in question and Please see similar issue I raised here: Gsettings does not work from inside a script - Desktop - GNOME Discourse Commented Mar 24, 2024 at 17:27
  • >there is no output< reload bashrc or restart bash Commented Mar 25, 2024 at 4:24
  • @yys2014 I reloaded bashrc, and rebooted my laptop, type Terminal shows the function definition but does not changes the Terminal theme! Commented Mar 25, 2024 at 11:54
  • >reloaded bashrc .. type Terminal shows the function definition< yes, it was about how to apply changes in bashrc Commented Mar 25, 2024 at 19:22
  • Bashrc does not always run, I had always problems with it. Commented Apr 2, 2024 at 8:23

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.