1

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.

1 Answer 1

0

Which version of Raspberry Pi OS? Which desktop environment are you using? Can't you just set a red image as your new background? That should be quite easy to do if you follow the documentation of your used desktop environment.

Then also just make a script that sets the background back to the default image, after each login (with rc.local or maybe even cron for example)

EDITTED MY ANSWER BASED ON YOUR COMMENT:

Could've guessed your OS from the original post (since you describe a path to LXDE).

The default Raspberry Pi OS uses a modified version of LXDE as desktop environment with Openbox stacking window manager, along with a unique theme.

Searching for lxde set desktop image on Google, gives a couple results you could try (also from RaspberrPi StackExchange, so this question is a duplicate): Change wallpaper in LXDE through terminal

They have discussed this problem, and debugged quite a few possible solutions.
Please mark as duplicate or solved if this helped you :)

2
  • I am using Raspberry Pi Legacy O/S based on Buster and whatever desktop comes with it. And that's the problem - despite my best efforts, I have not found any documentation that describes how to change the desktop's background color without using the desktop preferences dialog. Commented Mar 29, 2022 at 12:15
  • If by "programmatically" you mean a shell script, look at 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
    Commented Mar 29, 2022 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.