Xfconf-query sets current theme but Firefox is not updated unless the GUI is used

Hi all.

I’ve tried xfconf-query to set Xfce theme from the command line and it works well except with Firefox. I configured the latter to adapt to the current desktop theme by setting “Web site apparence” in “General” to auto. So when I use Xfce GUI to switch themes, Firefox does follow. When I use the above command line tool to do the same thing, it doesn’t.

Why’s that and how can I make Firefox react to switching themes from the command line?

Thanks in advance.

EDIT: for the record, here’s my script.

#!/bin/sh
#
# Toggle between light and dark Matcha themes for Xfce

# Fail on error
set -e

switch_theme()
{
        local theme="$1"
        xfconf-query -c xsettings -p /Net/ThemeName -s "${theme}" && \
        xfconf-query -c xfwm4 -p /general/theme -s "${theme}-hdpi"
}

CURRENT_THEME=$(xfconf-query -c xsettings -p /Net/ThemeName)
[ -n "$CURRENT_THEME" ] || {
        echo "Current theme does not exist"
        exit 1
}

# Swap current theme between dark and not dark
case "$CURRENT_THEME" in
        Matcha-dark-*)
                switch_theme "${CURRENT_THEME/dark-/}" ;;
        Matcha-*)
                switch_theme "${CURRENT_THEME/Matcha-/Matcha-dark-}" ;;
        *)
                echo "Theme '${CURRENT_THEME}' not supported"
esac

Hi @RygelXVI

Try: After change the theme to restart daemon

xfsettingsd --replace --daemon

Hi.

Nope, doesn’t do. And worse is that Firefox gets stuck to the previously applied theme. Usually I can switch to either “Clear” or “Dark” then to “Auto” and Firefox adapts to the desktop theme. If I run that command, it stays on the theme (e.g. “Clear” if I had selected that theme before). Running the GUI has Firefox adapt again.

Any hint as to why that command would not work? Is this the only possibility?

Question:

Do you restart firefox after theme change and theme not changing?

Or firefox theme not changing on the spot, when firefox is running.

The issue is that Firefox reads color-scheme through xdg-desktop-portal, which pulls from gsettings — not xfconf. The XFCE GUI updates both, xfconf-query only updates xfconf.

2 Likes

No, I don’t restart Firefox when I switch themes. I don’t have to when I use Xfce GUI so I want to achieve the same results programmatically, i.e. with a script.

Now that’s interesting :+1:

I have updated my initial post with the script in question. No idea why I skipped that in the first place ¯\_(ツ)_/¯