GNOME Desktop Background Picture of the Day
Unlike KDE Plasma, GNOME does not have a native feature to replace the desktop background with a “picture of the day”. KDE Plasma offers multiple sources to carry out this task natively (NASA, Bing, National Geographic, NOAA, Unsplash, Wikimedia Commons…). I’m sure there are several third-party plugins for GNOME that supply this function, plugins that tend to break GNOME every time there’s an update. The following is a script of just four lines that I usually use in workstations with GNOME.
Script to download a random image from picsum.photos :
#!/bin/sh
wget -O ~/.local/share/backgrounds/background.jpg https://picsum.photos/1920/1080
1920/1080
are the width and height in pixels of the image to download. I save the script in /home/miguel/.local/share/backgrounds/
where the downloaded image will also be saved with the name background.jpg
But this script has a problem: If at run time the wget
command fails (no internet connection, picsum.photos server not responding, etc.), an empty background.jpg
will be created, rewriting the previous image and showing a black background on the desktop. In order to solve it:
#!/bin/sh
if wget -O ~/.local/share/backgrounds/background-tmp.jpg https://picsum.photos/1920/1080
then mv ~/.local/share/backgrounds/background-tmp.jpg ~/.local/share/backgrounds/background.jpg
else rm ~/.local/share/backgrounds/background-tmp.jpg
fi
Now wget
will save the image to the file background-tmp.jpg
, if wget
succeeds it will move the file background-tmp.jpg
to background.jpg
and if it fails it will delete the empty file background-tmp.jpg
while keeping the old file background.jpg
.
In this example the home directory /home/miguel
is encrypted so that the periodic execution of the above script will not be performed neither by cron nor by systemd. It will be executed once when the user miguel logs in to GNOME and for this I create the following file that I will save in /home/miguel/.config/autostart/
with the name download-background.desktop
[Desktop Entry]
Type=Application
Name=DownloadBackground
GenericName=Download a wallpaper
Comment=Download a ramdom wallpaper.
Exec=/home/miguel/.local/share/backgrounds/download-background.sh
Terminal=false
Notice: ~/.local/...
will not work in Exec=
I check it:
I log out of GNOME and log back in. In an empty workspace, right-click, “Change background…”:
And I check that it has already found the downloaded image in ~/.local/share/backgrounds/background.jpg
on login (the photo of a jellyfish in this example):
I select it and that’s it: