Hey, I'm building a IoT device capturing the light in my room to switch the color theme.
I just don't know how to create the Zorin Appearance behaviour when switching Dark/Light Theme in the Terminal.
I tried:
# Set Dark theme
gsettings set org.gnome.desktop.interface gtk-theme ZorinBlue-Dark \
&& gsettings set org.gnome.desktop.interface icon-theme ZorinBlue-Dark \
&& gsettings set org.gnome.desktop.interface color-scheme prefer-dark
But just some elements are changing in the UI, how to complete the command?
If some are changing, the plan is working. But some elements may be Flatpak, Snaps or other and there also is a difference between GTK3 apps and GTK4 apps.
Okay, I found out when I modify the user-theme extension and additional set the theme with the gsettings it does change the apps I need and performs a clean theme switch.
So the working version is:
#! /bin/bash
THEME="ZorinBlue-Dark"
COLOR_THEME="prefer-dark"
# Set Dark theme
gsettings set org.gnome.desktop.interface gtk-theme $THEME && \
gsettings set org.gnome.desktop.interface color-scheme $COLOR_THEME && \
# https://askubuntu.com/questions/1375669/how-can-i-change-my-gnome-shell-theme-user-themes-extension-using-the-terminal
dconf write /org/gnome/shell/extensions/user-theme/name "'$THEME'"
Further reading:
When using crontab dconf needs an DBUS_SESSION_BUS_ADDRESS otherwise gnome does not know which desktop session to change; it could be any session, so I found this thread which helps: https://askubuntu.com/questions/1234742/automatic-light-dark-mode
There's no need to mess with dconf, there's a setting for the user theme as well:
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
gsettings set org.gnome.desktop.interface gtk-theme 'ZorinBlue-Dark'
gsettings set org.gnome.desktop.interface icon-theme 'ZorinBlue-Dark'
gsettings set org.gnome.shell.extensions.user-theme name 'ZorinBlue-Dark'
What do you mean? This seems to work fine for me. I wrote a little script to test this quickly:
#!/bin/bash
color=${1,,}
bg=${2,,}
if [[ -z "$bg" ]]; then
bg=$(gsettings get org.gnome.desktop.interface color-scheme)
bg=${bg//\'/}
bg=${bg/#*-}
fi
gsettings set org.gnome.desktop.interface gtk-theme "Zorin${color^}-${bg^}"
gsettings set org.gnome.desktop.interface icon-theme "Zorin${color^}-${bg^}"
gsettings set org.gnome.shell.extensions.user-theme name "Zorin${color^}-${bg^}"
gsettings set org.gnome.desktop.interface color-scheme "prefer-${bg}"
#! /bin/bash
color=${1,,}
bg=${2,,}
if [[ -z "$bg" ]]; then
bg=$(gsettings get org.gnome.desktop.interface color-scheme)
bg=${bg//\'/}
bg=${bg/#*-}
fi
gsettings set org.gnome.desktop.interface gtk-theme "Zorin${color^}-${bg^}"
gsettings set org.gnome.desktop.interface icon-theme "Zorin${color^}-${bg^}"
gsettings set org.gnome.shell.extensions.user-theme name "Zorin${color^}-${bg^}"
gsettings set org.gnome.desktop.interface color-scheme "prefer-${bg}"
Switching from light blue > dark gray, the script does not color all UI (example: virt-manager gui):
I think the next command in the sequence is overriding the settings of the previous command.
When having the order correct like in your previous post or below:
new_color_theme="prefer-dark"
new_gtk_theme="ZorinGrey-Dark"
gsettings set org.gnome.desktop.interface color-scheme ${new_color_theme}
gsettings set org.gnome.desktop.interface gtk-theme ${new_gtk_theme}
gsettings set org.gnome.desktop.interface icon-theme ${new_gtk_theme}
gsettings set org.gnome.shell.extensions.user-theme name ${new_gtk_theme}
It does work without any problems and every UI is updating...
I have to say I run a startup script every time I install Zorin on my PC it does a lot of tweaking, have not tested it on a Vanilla version.
Watch out: you typed gray, with an "a". But the theme is as you wrote it in the script down below, with an "e". Here's a revised version to help with that kind of typo:
#!/bin/bash
color=${1,,}
bg=${2,,}
if [[ "$color" = "gray" ]]; then
color=grey
fi
if [[ -z "$bg" ]]; then
bg=$(gsettings get org.gnome.desktop.interface color-scheme)
bg=${bg//\'/}
bg=${bg/#*-}
if [[ "$bg" = default ]]; then
bg=light
fi
fi
gtk_theme="Zorin${color^}-${bg^}"
icon_theme="Zorin${color^}-${bg^}"
gsettings set org.gnome.desktop.interface gtk-theme "${gtk_theme}"
gsettings set org.gnome.desktop.interface icon-theme "${icon_theme}"
gsettings set org.gnome.shell.extensions.user-theme name "${gtk_theme}"
gsettings set org.gnome.desktop.interface color-scheme "prefer-${bg}"
I've also ran this on a fresh install where the color-scheme property is set to "Default". I'm not sure what that's supposed to be but I assume it must be "light" since that's what the system looks like, so I'm also accounting for that, so it should work even on fresh installation of Zorin OS.
This could use some improving if you intend to actually use it long term, though. Like checking that the values provided match the ones available, for example.
Grey has always been how we spell it. However we're in Canada. I know in the states it's very much always spelled Gray. Makes a lot of our day to day fun, because depending on what we're looking at came from, the spellings for many things are different.
I had to look this up; given that as a US Citizen, I have only been taught "American English."
It seems like "Colour" and "Color"; This is a Noah Webster change introduced in A Compendious Dictionary of the English Language, though the spelling as gray existed already, he solidified it in the USA as the "American" way, separating from Britain's 'English.'
Yep. Quite a few differences are his doing. There's a YouTube channel I sometimes enjoy called Lost in the Pond which highlights differences between living in the UK and US. Words come up fairly often, and the channel has more than once cited Webster as the source of a difference. The host is a British ex-pat, now a naturalized US citizen, and takes a rational position on language differences and influences rather than the "There's British English and wrong" stance you sometimes get.
I never once understood why the USA has to be so different then Britain, when it comes to English spoken. USA don't even say the word aluminum, in the same way as British folks do.
USA is so well known for these kinds of things. Another example, we use "F" in measuring our temperature scale, rest of the world uses "C." Life would be easier if we all used the same thing.
I've noticed on many websites where you choose your language, some differentiate USA English, & British English. Thats because there is a vast difference in how we speak, and our slang used.
Oh yes... grey or gray lol ... I can not reproduce the bug, it is something which happens when the PC is running a whole day and the dark mode kicks in with crontab, changing the order did solve it for me.
This is my script:
(I need to get the session address because it is crontab and not the terminal)
#! /bin/bash
# Get the night status from the web ( 0 or 1 ) > TODO: Make rest api
URL="removed"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# https://askubuntu.com/questions/1234742/automatic-light-dark-mode
set_theme() {
# https://askubuntu.com/a/743024/1193214
# PID may return multiple ids here, so I converted to to array and got just the first id.
# Otherwise, you may try another suggestion in the link https://askubuntu.com/a/1437023/1193214
PID=($(pgrep gnome-session))
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
new_color_theme="$1"
new_gtk_theme="$2"
# https://askubuntu.com/a/1234819/895417
export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
echo "[-] Setting gtk theme to ${new_gtk_theme}"
# https://forum.zorin.com/t/how-to-switch-dark-light-theme-with-the-terminal/48920/5
# ORDER 1
gsettings set org.gnome.desktop.interface color-scheme ${new_color_theme}
gsettings set org.gnome.desktop.interface gtk-theme ${new_gtk_theme}
gsettings set org.gnome.desktop.interface icon-theme ${new_gtk_theme}
gsettings set org.gnome.shell.extensions.user-theme name ${new_gtk_theme}
}
cd $SCRIPT_DIR
rm ${URL##*/}
wget -q $URL
IS_DARK=`cat ${URL##*/}`
#IS_DARK=1
# echo "It is dark:" $IS_DARK
if [ -n "${IS_DARK}" ];
then
IS_DARK_BK="-1"
if [ -e bk_${URL##*/} ]
then
IS_DARK_BK=`cat bk_${URL##*/}`
fi
if (($IS_DARK != $IS_DARK_BK))
then
if (($IS_DARK > 0))
then
# dark
set_theme "prefer-dark" "ZorinGrey-Dark"
else
# light
set_theme "prefer-light" "ZorinBlue-Light"
fi
fi
echo "${IS_DARK}" > bk_${URL##*/}
fi
Changing IS_DARK will set the theme here, it might getting the wrong PID?
EDIT: Getting the UID with the PID is probably bad practice ... so I changed it to: export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u $USER)/bus"
I see in the following days if it happens again
Here is the edited version:
#! /bin/bash
set_theme() {
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u $USER)/bus"
new_color_theme="$1"
new_gtk_theme="$2"
# https://forum.zorin.com/t/how-to-switch-dark-light-theme-with-the-terminal/48920/5
gsettings set org.gnome.desktop.interface color-scheme ${new_color_theme}
gsettings set org.gnome.desktop.interface gtk-theme ${new_gtk_theme}
gsettings set org.gnome.desktop.interface icon-theme ${new_gtk_theme}
gsettings set org.gnome.shell.extensions.user-theme name ${new_gtk_theme}
}
# dark
set_theme "prefer-dark" "ZorinGrey-Dark"
# light
# set_theme "prefer-light" "ZorinBlue-Light"