I have a script that sets one exact image as a wallpaper and I want it to check at every run if it's still the same image. If not, it asks you if you want to change wallpaper again to this image. It's a part of bigger project and for now it works like this:

  1. script detects if there is a .config.txt file in user directory
  2. if not, it asks you if you want to change your background
  3. .config.txt is created during this process

I have searched an answer to this question all over internet. Unfortunately most of the topics relate to Ubuntu and they're not helpful at all. I have tried locate backgrounds command but I don't see anything legit and oh boy, I've searched most of listed directories. I've been searching in .cache too, but still nothing.

  • GNOME 3, script sets wallpaper with gsettings set org.gnome.desktop.background picture-uri file:///path/to/the/file Overall it works great, but I have a difficulty with detecting if file is still a background as I have mentioned before. I have implemented .config.txt as a temporary solution. Sep 8, 2016 at 21:49
  • Thanks a lot for this command! Now I only need to implement diff function that will compare output of the command to pattern of my selection. It still leaves a possibility of changing wallpaper and naming it the same as my file, and that's a thing I can figure out with comparing histograms of pics but anyway, for now gsetings get will do well I think. Thanks! Sep 9, 2016 at 13:34

2 Answers 2


The stock Kali wallpapers images are stored in:


The current wallpaper is set by linking /etc/alternatives/desktop-background to whichever .png file in /usr/share/images/desktop-base/ that you would like to set it as; although you could link it to a .png file in any other folder that you choose.


If you can set the file with

gsettings set org.gnome.desktop.background picture-uri file:///path/to/the/file

then you can get the file with

gsettings get org.gnome.desktop.background picture-uri

That will give you a string like 'file:///usr/share/images/desktop-base/desktop-background.xml' which is nice but needs to be parsed before we can directly use it as an argument to another shell command. So we can easily strip out the quotes and the file:// part with cut, like:

gsettings get org.gnome.desktop.background picture-uri | cut -d/ -f3- | cut -d\' -f1

(Note: the returned file is actually an XML file for me, but I'm not using GNOME, so I don't know how this works on a live system. There may be another processing step that needs to happen here, before you can start comparing files.)

And since you already know the name of the file you want to compare against, you can use cmp to compare those two files:

cmp my/file.jpg "$(gsettings get org.gnome.desktop.background picture-uri | cut -d/ -f3- | cut -d\' -f1)"

cmp will set a return value of 0 (true), if the files are the same, or non-zero (false) if they're different or something went wrong. We can use that to decide what to do next, perhaps using the || operator which will run a command only if the previous command returned non-zero (false). We can also suppress the output from cmp with the -s switch. That gives us this command that you could, for example, run as a regular cron job:

cmp -s my/file.jpg "$(gsettings get org.gnome.desktop.background picture-uri | cut -d/ -f3- | cut -d\' -f1)" || gsettings set org.gnome.desktop.background picture-uri file:///full/path/to/my/file.jpg

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .