So, I was binge-watching YouTube videos and a random thought came to my mind, like most people: What if I write a bash script to change the wallpaper every minute? I will be like the wallpaper slideshow in Windows. So I got into writing a script. I was quite straightforward. And you can find the final script in my GitHub Repository.
So first off, how do you change the wallpaper in Linux? Well, it depends on the distro! Since Ubuntu is a common distro and it’s based on Gnome, you can use the Settings app to change the wallpaper. The same goes for most other famous distros.
But this lacks the option to time the changing of the wallpaper, which is kind of boring. Now I’ve got to admit, there might be better options for wallpaper slideshows in Linux. Having a script is not at all optimized let alone elegant. But I like the simplicity of the idea.
Now if we want to automate the wallpaper creation, we must first have a command that can change the wallpaper. In fact, we do!
gsettings set org.gnome.desktop.background picture-uri-dark /path/to/wallpaper.jpg
Now this is for the dark theme, for the light theme, it’s the same but as below.
gsettings set org.gnome.desktop.background picture-uri /path/to/wallpaper.jpg
Now it’s a matter of adding the sleep and an indefinite loop.
We want to be able to run this script automatically on startup. Clone the components from the GitHub repo. If you do not know how to clone the repo, you can also download a release from Releases. It is recommended to download the latest version.
Create a directory in ~/Pictures/
called Wallpapers
. Copy the required wallpapers to this directory.
Copy the change_wallpaper.sh
to a convenient location, possibly to your home (~
) directory. Open a terminal from the copied location. Enter the following command to make the script run automatically on startup.
SCRIPT_PATH="$PWD/change_wallpaper.sh"; SERVICE_NAME="change_wallpaper.service"; chmod +x $SCRIPT_PATH; echo "[Unit]
Description=My Script
After=network.target
[Service]
ExecStart=$SCRIPT_PATH
[Install]
WantedBy=default.target
" | tee ~/.config/systemd/user/"$SERVICE_NAME"; systemctl --user daemon-reload; systemctl --user enable "$SERVICE_NAME"; systemctl --user start "$SERVICE_NAME"
You have to make sure not to run this command with sudo
privileges. That should give you a wallpaper slideshow!
Now it would be boring to have a script that doesn’t have any customization options, so I included additional features to the script as well. Adding additional wallpapers is as simple as copying them to the Wallpapers
directory. Both JPEG and PNG wallpapers are supported.
You can also customize the script to your liking. Simply open the script in a text editor and change the following variables:
wallpaper_path="/home/$USER/Pictures/Wallpapers"
- Wallpaper path: The wallpapers must be in a directory. Enter the directory path here between double quotes. Do not enter the path to a file. Make sure to provide an absolute path relative to the root.update_wallpaper_every=10m
- Time to update the wallpaper: Replace10m
with your own value. This can be given as: s or (no suffix): seconds (default), m: minutes, h: hours, d: days. Decimals and combinations are also accepted. For example:update_wallpaper_every=5
: 5 seconds,update_wallpaper_every=5s
: 5 seconds,update_wallpaper_every=2m
: 2 minutes,update_wallpaper_every=1.5h
: 1.5 hours,update_wallpaper_every=7d
: 7 days,update_wallpaper_every=1h30m
: 1 hour and 30 minutes. It is recommended to provide a time greater than 5 seconds. The script is also not set to persist time every reboot. Therefore might not change the wallpapers properly for higher timeframes.update_list_every=5
- Number of times to wait to update the list of images: This will wait until the given number of times of wallpaper updates to update the list of images in the wallpaper path. For example ifupdate_wallpaper_every=10m
andupdate_list_every=5
, the list of wallpapers will be updated every 50 minutes.
Further modifications can be done to the script itself if needed.
Now there are cases where you might want to temporarily stop the script or permanently get rid of it. So:
In case you want to pause the changing of wallpapers, you can create a file called
.override
inside the sameWallpapers
directory which will pause the slideshow indefinitely until the file is deleted again.You can check the status of the script by using the following command.
systemctl --user status "change_wallpaper.service"
NOTE: Do not run this command with
sudo
.
- The script can be temporarily stopped by killing the script.
sudo kill -9 $(ps -eo pid,command | grep /bin/bash | grep live_wallpaper_script.sh | tr -d " " | tr "/" "\n" | head -n 1)
NOTE: Have to run this command with
sudo
.
- The script can be permanently stopped and removed by deleting the service file.
SERVICE_NAME="change_wallpaper.service"; systemctl --user stop $SERVICE_NAME; systemctl --user disable $SERVICE_NAME; rm ~/.config/systemd/user/"$SERVICE_NAME"
NOTE: Do not run this command with
sudo
.
- In case the script is modified, the service can be restarted to pull updates to the script.
systemctl --user restart "change_wallpaper.service"
NOTE: Do not run this command with
sudo
.
To report bugs and request features, go to GitHub issues and create a new Issue. Make sure to include the terminal output and a clear explanation of what you were trying to do and what happened. Also, include device information such as the distro and install path. It will take some time to provide support.
Anyone can contribute to this project. If you're a bash programmer, any new features or bug fixes are greatly appreciated. Any suggestions are also appreciated along with documentation improvements. The same goes for any bug reporting and feature suggestions. Also, if you're willing to, consider trying all features of this script in your distro and providing any feedback; especially if you're on a different distro.
I ran the script on Ubuntu 24.10.