r/xfce • • 2d ago

theme toggle for xfce

everytime I want to switch to dark mode or light mode, I have to open settings - appearance.

so i asked gemini to make a script that will setup a toggle icon in xfce panel for switching theme mode (dark/light) and it works well. if you want to try here's the link

https://github.com/soybi/my-scripts/blob/main/setup-toggle-xfce-theme.sh

check Readme.md for details

Edit: updated the setup script, and made a reversal script. removed the hard coded default theme and made it fallback to adwaita and elementary. thank you guys for the feedback. please let me know if there is any issue. i ran it in my cachy os main machine and it worked for me really well.

1 Upvotes

16 comments sorted by

5

u/cincuentaanos Xubuntu 2d ago

Here's mine, very straightforward and doesn't do a lot of checks. Just toggles between two themes:

#!/usr/bin/bash

if [ $(xfconf-query -c xsettings -p /Net/ThemeName) == "Greybird" ]; then

    xfconf-query -c xsettings -p /Net/ThemeName -s "Greybird-dark"
    xfconf-query -c xfwm4 -p /general/theme -s "Greybird-dark-accessibility"
    dconf write /org/gnome/desktop/interface/color-scheme "'prefer-dark'"

else

    xfconf-query -c xsettings -p /Net/ThemeName -s "Greybird"
    xfconf-query -c xfwm4 -p /general/theme -s "Greybird-accessibility"
    dconf write /org/gnome/desktop/interface/color-scheme "'prefer-light'"

fi

1

u/iamSoybi 2d ago

Nice and clean! Using dconf write directly for color-scheme is a great trick too—I might add that as a fallback in mine in case gsettings isn't available on minimal installs.

1

u/iamSoybi 2d ago edited 2d ago

i updated my script to include your dconf write trick. thank you for sharing! i want my script to work in any xfce setup. even if it's just a theme toggle, it actually adds some quality of life improvements when using my computer (specially for my wife, she likes light theme, and i'm the opposite) 😂

2

u/cincuentaanos Xubuntu 2d ago

Personally I like a light theme during the day and a dark one at night. So that's why I made the script and a starter on the panel bar for it, so I can easily swith whenever I like.

If your wife has her own user account on the computer she can have her own preferences and layouts etc. without interfering with yours.

1

u/iamSoybi 2d ago

For our use case we only need it on-demand. That's why I thought of making a script that toggles the theme instead of automated one. Btw just a disclaimer, i'm not a programmer by any means. Thank you for sharing your knowledge and insights!

3

u/Headpuncher Xubuntu 2d ago edited 2d ago

First issue I see is I don't have any of your defaults, style theme or icons installed and they're hard-coded into the script. The XFCE settings > Appearance has defaults, so the script should probably look for those and not something system specific.

I think you've confused XFCE with your computer.

1

u/iamSoybi 2d ago

sorry about that and thank you for feedback, i updated it to fallback to adwaita theme and elementary icon theme instead. let me know any issues

1

u/iamSoybi 2d ago

here's a video of how it works. this is my main machine. 🎉

1

u/callusbonus1967 2d ago

Problema tendría que estar usando los mismos temas que tú script o tengo que modificarlo entero para mis temas al uso. Gracias.

1

u/iamSoybi 2d ago

setup-toggle-xfce-theme.sh

Automated setup script that installs a 1-click Light/Dark theme switcher (~/.local/bin/toggle-xfce-theme.sh) and adds a corresponding toggle button directly to the XFCE Panel.

Features:

  • Full Desktop Toggle: Automatically detects your active GTK style, window manager borders, and icon theme (-light/-dark variants with fallback defaults) and switches them simultaneously via xfconf-query without altering your wallpaper, while syncing the XDG color-scheme via gsettings so Firefox and GTK4/libadwaita apps follow the toggle.
  • 1-Click Panel Integration: Automatically creates the .desktop launcher entry and registers it on panel-1 so you can flip themes from the panel with zero background RAM usage.

1

u/callusbonus1967 2d ago

Tendría que añadirlo al arranque en el inicio supongo? Para que esté activo todo el tiempo?

1

u/iamSoybi 2d ago

no you don't have to. it's just a toggle switch for dark theme and light theme. assuming your theme has dark and light variant. just run the script and it will set it up for you. after setup just click the icon from the panel.

1

u/Responsible-Sir-5994 2d ago

Darman

1

u/iamSoybi 2d ago

what?

1

u/Responsible-Sir-5994 2d ago

Script switcher for sunset/sunrise

1

u/iamSoybi 2d ago

oh it's an app. thank you for letting me know. that one is automated which is also nice.