i really do love KDE and it’s breeze themes. since i desired to have a function known from IOS, to switch themes according to the sunlight, i discovered a few more complex solutions, and a KDE feature request.
but as a minimalist, i wanted a lighter approach. by discovering the lookandfeeltool capable of changing the gloabel theme, the rest was just a bit of bash and GPT.
so, here is my solution, which may eventually be usefull for others (like myself 30min ago) (-:
#!/bin/bash
# theme_switcher v 2.0
# Get the current time in 24-hour format (HHMM)
current_time=$(date +"%H%M")
# Define the threshold times without leading zeros
morning_time=900
evening_time=1700
# Check the time and echo the appropriate message, forcing base-10 interpretation
# grep if to be applied daytheme isn't already active - if not, set it per lookandfeel command
if [[ $((10#$current_time)) -ge $((10#$morning_time)) && $((10#$current_time)) -lt $((10#$evening_time)) ]]; then
grep -q "LookAndFeelPackage=org.kde.breeze.desktop" ~/.config/kdeglobals || lookandfeeltool -a org.kde.breeze.desktop
elif [[ $((10#$current_time)) -ge $((10#$evening_time)) ]]; then
grep -q "LookAndFeelPackage=org.kde.breezedark.desktop" ~/.config/kdeglobals || lookandfeeltool -a org.kde.breezedark.desktop
fi
exit 0
i checked the boot times as well, using"logger -t" and having this as autostart, it needs around 0.75s if changing the theme, and less then 1ms if not.
i may add a kind of “wget weather.com | grep sunset & sundawn” to autoset the thresholdtimes as well…
have fun everybody and thatnks a lot for this beautifull KDE Plasma!!!
you can use the following, to use a the webcam to sense the surrounding light as a trigger:
#!/bin/bash
# Capture an image
ffmpeg -y -f video4linux2 -i /dev/video0 -frames 1 snapshot.jpg > /dev/null 2>&1
# Calculate brightness
brightness=$(convert snapshot.jpg -colorspace Gray -format "%[fx:mean]" info:)
# Define threshold
threshold=0.5 # Adjust this based on your preference
# Check brightness and set theme
if (( $(echo "$brightness > $threshold" | bc -l) )); then
echo "L I G H T"
# Command to set light theme
else
echo "D A R K"
# Command to set dark theme
fi
sorry, i was not thinking about users who may have not used scripts before, so here is a how-to for somebody not familiar with bash scripts.
use an editor (e.g. kate or nano) and paste the code from the codebox of post #1 into it.
now save the script e.g. in your /home folder and name it: “anynameyouwant.sh”
to make the script executable, you have to set according permissions: either by
a. right click the file → properties → permissions checkbox: “is executable” or
b. “chmod +x yournameofthescript.sh” in a terminal
Now, you’ve an executable script. you can try it out running it by executing it, for example like this: “./yournameofthescript.sh”
You can now adjust the times where the sun sets and dawns in the script, behind the “morning_ and evening_times”.
Now, to autostart the script on boot, simply search for “autostart” in your KDE menu, click it, and add the script with your given name.
There is a plasmoid colorschemeswapper-plasmoid, that allow to change theme manually. It would be great if it will be extended by this script and allow additionally to change theme automatically.
This can all be put in a desktop application. Don’t really have to wait for the plasmoid to be updated. Same for colorscheme, icons…All in one.
Separate stuff, colorscheme+icons, c+i+ wallpaper etc…Something along these lines…