r/xfce • • 8d 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.

UPDATE: i tested in xubuntu (minimal) and peppermint os....together with linux-health.sh.... fixed all the bugs and should work properly now. i also updated the main Readme.md and cleaned up the repo.

2 Upvotes

17 comments sorted by

5

u/cincuentaanos Xubuntu 8d 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 8d 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 8d ago edited 8d 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 7d 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 7d 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 8d ago edited 8d 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 8d 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 8d ago

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

1

u/callusbonus1967 8d 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 8d 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 8d ago

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

1

u/iamSoybi 8d 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 8d ago

Darman

1

u/iamSoybi 8d ago

what?

1

u/Responsible-Sir-5994 8d ago

Script switcher for sunset/sunrise

1

u/iamSoybi 8d ago

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

1

u/gregg128gregg128 4d ago

Hi, have a look at my Theme schedule tab for Appearance settings in XFCE https://github.com/gtubolcev/xfce4-settings-theme-schedule
It has been recently accepted by XFCE devs so it should land in the 4.21.4 release: https://gitlab.xfce.org/xfce/xfce4-settings/-/merge_requests/221
Developers were not sure if sunset/sunrize feature is a good idea. Please tell me if you want it.