1

Background

I have a small script that changes my wallpaper to a random image:

#!/bin/bash
feh --randomize --bg-fill /home/USERNAME/Pictures/wallpapers/*

It works like a charm, so I decided to add it to the startup applications, like in this question:

Problem

Everything works fine except for one problem:

  • On start up, the wallpaper is changed via the script, as expected. Then, seconds after, Ubuntu takes over and replaces that wallpaper with the default one.

Question

How can I keep this from happening?

1 Answer 1

1

Why Wallpaper is Replaced

Long story short, when you have desktop icons enabled, that essentially enables Nautilus to create the Desktop "window" with all the file and folder icons and manage background. feh works with raw X11 desktop, i.e. bare bones, where no icons exist. So there's two potential solutions: one is to rely on Ubuntu's settings for background, or two - disable desktop icons. One can also make a script to launch both feh and alter Ubuntu desktop settings, but that's redundant in my opinion. Whichever way you decide to go is up to you

Disabling/Enabling icons

This can be done via gsettings org.gnome.desktop.background show-desktop-icons false to disable and org.gnome.desktop.background show-desktop-icons true to enable. Once that's done Nautilus won't manage your desktop, hence won't set the background picture

Ubuntu Wallpaper Settings

Aside from obvious GUI methods, one can use gsettings command to set the wallpaper.

gsettings set org.gnome.desktop.background picture-uri file:///home/my_user/Pictures/cool_wallpaper.png

Of course, previously mentioned caveat applies - the desktop icons have to be enabled.

Alternative to Your Script

I have noticed that you are trying to set a random wallpaper from a folder. You don't have to rely on feh for that. In the past, I've written two scripts to do this task. One written as bash script and another one as Python script. Both scripts work with Ubuntu's gsettings and alter the desktop wallpaper without disabling icons. Personally, I'd suggest the Python one as it is more polished.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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