I’ve recently been exploring the world of Gnome 3 inside my Antergos Linux computer. Since Antergos is slightly different than Arch I do not know if this will work with an Arch system or not, but it sure works on my Antergos system. A copy of this tutorial can be found here, and also on my blog at RationalThinking101.com, just in case (inevitable) I have to reinstall and lose this configuration then I can find it here, and you can use it too! ;)
My mission in this tutorial: Show step by step how you can get Gnome to rotate your desktop wallpaper regularly and automatically. Forgive me if this tutorial is too verbose.
Please note although I am running Antergos, my system may be different than your system. I may have encountered problems that you will not encounter or visa versa. In my initial Antergos installation, I chose Xfce as my desktop environment. I added Gnome to my setup later on. That may make my system slightly different from yours. This tutorial works on my computer. It will probably work on yours if you use Antergos. It might even work for you if you run Manjaro or Arch. I do not know. You can change the instructions below at your own risk. This is what I did and if you do exactly like this it’s going to work on Antergos.
Step 1: Have a Wallpaper folder with pictures in it
On my computer I have created a Wallpaper folder inside Pictures. I regularly search Google images for “nature” and specify to show me images larger than 2 mb. I add images to this folder all the time. However you collect your wallpaper pictures is really up to you. This tutorial assumes you already have a bunch of your own wallpaper pictures and you have them stored in ./Pictures/Wallpaper
Step 2: Create a script
a. open a terminal. Create a folder in your home folder.
Close your terminal and go back to your desktop.
b. Open mousepad. You can find it by listing all of your Gnome programs. If you do not have mousepad (maybe your Gnome didn’t come with that text editor), then go and install it.
Once mousepad is open, you’ll have a blank screen. Copy the following code and paste it into your blank mousepad window:
#!/usr/bin/sh /home/[user]/Pictures/Wallpaper/ | shuf -n 1)'"' PID=$(pgrep gnome-session) export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-) gsettings=dconf gsettings set org.gnome.desktop.background picture-uri '"file://'/home/[user]/Pictures/Wallpaper/$(ls /home/[user]/Pictures/Wallpaper/|shuf -n 1)'"'
Do not remove the first line: #!/usr/bin/sh – that has to be there exactly as written.
Once you paste this into mousepad, you have to edit it. There are exactly 3 times the following text appears in this file: [user]. You have to replace [user] with your Linux username. Brackets and all should go. So if your username is “samantha” you will replace [user] with samantha. Make sure you get all three of them.
c. Save the script
We will now save this file. Save the file with this name: ~/bin/rotate_bg.sh
Close mousepad. Your script is created as a text file called rotate_bg.sh and it is stored in a folder “bin” inside your home directory.
d. Make the script executable
Now we must make the script executable in order for it to be useful. To do that, open a terminal and enter this command:
chmod u+x ~/bin/rotate_bg.sh
Still inside the terminal, test the script to see if it works. If it doesn’t you did something wrong from above and you need to go back and figure out where your mistake is. To see if the script successfully changes your Gnome desktop wallpaper, simply run it. Paste this into your terminal then press enter. Did your gnome wallpaper change? It does on mine, it should on yours.
Step 3: Make sure you have crond installed on your system.
In my case, crontab was not preinstalled on my Antergos system. I had to install it, and reboot, start it, reboot. It seemed like everything I did with it I had to reboot to get it to work. I don’t know if that’s normal or necessary, but it now works over here, even if I reboot, without further fussing with it.
crond is the daemon for cron, and crontab is a file for cron to follow when it’s running. I got it from the regular repositories.
Open the Antergos Add/Remove Software tool and search for “crond” - I wound up with a package called vixie-cron. I installed that. If you cannot find that specific package with your Add/Remove software tool, look in AUR. See if searching for crontab works. As stated, I installed vixie-cron.
Then you could reboot. Or you can carry on. If you reboot, don’t loose this tutorial. Bookmark it or something.
Step 4: start cron
Open a terminal, log on as root, and start cron. Don’t use sudo for this. Login with su.
su cron start exit
If you get an error message you should reboot and try again. When I say reboot, by the way, I do mean reboot. I don’t mean logout.
Step 5: Make a schedule to run your script
To make your desktop wallpaper script run regularly you have to edit crontab for your username. In the below example, replace [user] with your Linux username. Remove the brackets while you’re at it.
sudo crontab -u [user] -e
Example: Again, if your username is “samantha” it will look like this.
sudo crontab -u samantha -e
This will open your default text file editing program. Paste the following into it. Make sure you replace [user] with your username.
# (m) (h) (dom) (dow) (command) # * * * * * /home/[user]/bin/rotate_bg.sh
You need to understand what’s going on here because this may not be what you want. This tells cron to run your script every minute of every day. Your desktop wallpaper will change a lot, frequently. This is good for testing purposes, but later you might want to change it to every 10 minutes or once an hour. I’ll show you below how to do that. First thing first.
Save and exit. For me it would be Ctrl-X - accept the default file name, do not change the name - and then save and back to your command prompt.
Bookmark this tutorial, reboot your computer and log back into Gnome. Sit back and enjoy the show.
Step 6: Change Wallpaper from every minute to once every 10 minutes or once an hour.
If all goes well and it’s working correctly, you may want to go back and edit your crontab using the sudo crontab -u [user] -e command. If you want to run it only once each hour, you have to set the first item on the line (*) to something else other than *, for example:
20 * * * * /home/[user]/bin/rotate_bg.sh
The above example will change your wallpaper 20 minutes after every hour of every day.
Suppose you want to run it once every 10 minutes:
*/10 * * * * /path/to/script (change /path/to/script to the correct directory where rotate_bg.sh is located).
That’s it. Good luck.
Now, there is another way to get this to work using systemd. The problem with the above method is that it doesn’t seem to stick after a reboot. After each reboot you have to drop to a terminal and type “sudo cron start”
The other way, which will work even if you reboot, is discussed in this second tutorial.