How to switch Dark/Light theme with the Terminal?

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?

@Aravisian might be able to help you with that, as he's our resident terminal wizard. :mage:

Its not hard to switch to dark mode using the UI though, just go to Zorin Appearance...


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.

Oh I see this script getting longer... are there commands exposed from Zorin Appearance which could simplify this process?

example:
zorin-appearance --set-color-theme dark

If there are none it might be a great idea for Zorin 18?

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'
1 Like