A similar question, (How do I change the Desktop wallpaper from the cli), was asked previously where the person wanted to know how to change the wallpaper.
Going through the answers, I discovered that there is a file,
/home/pi/.config/pcmanfm/LXDE-pi/desktop-items-0.conf
In my case it contains the line desktop_bg=#7f7f7f7f7f7f which represents a medium grey desktop. (I've turned the wallpapers off).
What I want to do is change that background color to a different one programmatically, such that the original color will return when rebooted.
I have a Raspberry Pi that is running off of an external battery and I have a program, (that already works), that measures the battery's voltage and - when it drops below a certain point - displays a warning message and then still later, if the voltage has dropped near the point where the battery will shut itself off, it commands a system shutdown.
What I want to do is - when the battery voltage drops to the "warning voltage" - have my battery monitor program change the desktop's background to red. Ideally, this would persist until the next reboot whereupon the desktop background would return to the previously set color.
I can change the desktop_bg value in the file and save it. The next time I open the desktop preferences, I see the new color selected and when I click "OK", the new color is set.
What I want to know is how to set the color on demand without having to use the desktop preferences dialog.
man xsetroot. If you mean some other context, you might as well just execute that as a process since performance is obviously not an issue, but if you want to be more formal look into xlib. – goldilocks Mar 29 '22 at 13:54