Scripting a way to set the background color in Lubuntu 22.04

Okay, after viewing several man pages, forums, web pages, help files, and so forth and not finding the answer I was looking for, I’m posting this here.

I migrated over from GNOME, and already wrote a script using the command “gsettings set org.gnome.desktop.background primary-color <#RRGGBB>” to set the background color, in my case as a login script and set it depending on the day of the week. However I found with version 42 GNOME ended this ability, which prompted a search for an alternative DE, and I wound up landing on LXQt, used by Lubuntu.

I found the background color value is stored in /home//.config/pcmanfm-qt/lxqt/settings.conf and in fact is the first value in the [Desktop] section.

I also know if I right click on the desktop and choose “Desktop Preferences” I can manually set the background color. I also found typing “pcmanfm-qt --desktop-pref desktop perferences” will bring up the popup that allows for changing the background color. So obviously some kind of code to do this exists. But so far, I’ve been unable to uncover what command to give what module.

In summary, does anybody know how to set the desktop background color from the command line for Lubuntu 22.04?

You’ve done your homework well sofar. I guess that not many people require direct command line access to your requested feature, so probably it doesn’t exist. The easiest and quickest way around this is just to let sed do the job.

I’ll have to look into that. I’ve never used sed before.

sed is part of the suite of simple but very efficient Linux command line tools, which form together a true Swiss knife. It is mostly used for simple changes in existing text files, and ideal for scripting. If you need help, please let me know.

1 Like

Here’s a hacky way to do it during login, although there is a bit of a delay.

  1. Create this script and put it somewhere;
    e.g (make sure it’s executable)

T=$(date +"%H%M")

if [ "$T" -lt "1900" ]; then
   pcmanfm-qt -w $HOME/Pictures/wallpapers/day.jpg
   pcmanfm-qt -w $HOME/Pictures/wallpapers/night.png
  1. Preferences > LXQt Settings > Session Settings > Autostart
    2a. Click once LXQT Autostart. Then Add.
    Name: Change Wallpaper
    Command: for the script above.
    Wait for system tray : Yes

  2. Edit /.config/autostart/lxqt-desktop.desktop
    and change
    Exec=pcmanfm-qt --desktop --profile=lxqt
    Exec=pcmanfm-qt --desktop --profile=lxqt -w /dev/null
    (this will blank out the previous desktop so that it won’t flash during login).

1 Like

Perhaps humpty’s solution. it is not exactly what zon14 wants. His use case is to have a different background colour every time the day changes on a running system. And not a different wallpaper image when the login is after an arbitrary moment.

It is possible to have a plain colour on your desktop (instead of an(y) image). The configuration wizard has rudimentary support for that in the background tab: 1) select a colour; 2) introduce a non-existing pathname for the (non-required) wallpaper file. Strange, but this is the way it works (in lxqt 0.16.0).

The actual value of the colour for the background is stored in a configuration file, which can be easily modified with e.g. sed in a bash script file which is triggered with cron.

I’ll only have to find out in which file the information is stored :wink:



You would have to killall pcmanfm-qt before you edit the file or it will be re-written.

1 Like

Thanks. A bit of anomaly in the location of that file.

Yeah. sed would be useful for writing to the config file, but would require a restart of pcmanfm-qt. I had one other idea. Is there a scripting command the equivalent of Windows sendkeys? I’ve already proven to myself I can open the change background color dialog. It’d be sending a bunch of tabs and returns first, then overwriting the box with the color value, then returning over Okay, okay, etc. That would work, if it’s available.

Nice thinking. Sorry, I don’t have the time right now to think with you.

I didn’t quite like having to restart pcmanfm-qt either.

Here’s another way to do it with a wallpaper. Basically you generate a one pixel image with a color you want and tile it.

Here is the script;

# Generate a single pixel and tile it as a wallpaper

# You can use hex colors (#)
# or X11 color names
COLOR="Light Steel Blue"

echo "/* XPM */
static char *dot_xpm[] = {
/* width height num_colors chars_per_pixel */
\"     1     1      1            1\",
/* colors */
\"a c $COLOR\",
/* pixels */
};" > ~/Pictures/dot.xpm

pcmanfm-qt --wallpaper-mode=tile -w ~/Pictures/dot.xpm
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.