• Tutorial: Automatically rotate Gnome Wallpaper

    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.

    mkdir bin

    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:

    /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.

    cron start

    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.

  • @shwaybotx , hi! Doesn t this deserve its own place in our wiki!👍
    What do you think?

  • @anarch
    I’m honored that you think so. Of course. I worked pretty hard putting that together. Can you do that? That’s a huge wiki. I wouldn’t want to touch it myself.

    (And can you give me something other than “newbie” status on this forum please?)

  • @shwaybotx I’m newbie to linux, so i don’t understand exactly all the script’s commands, but i would like to ask you:
    Isn’t easier to add a loop in you script like while : etc and a sleep command to avoid installing crontab (just to make everything work inside the very same script)?
    Then just autostart the script at login?
    Not sure if what i’m saying is logic.
    Anyway i’m happy about your script, although i don’t use Gnome i saw a lot of users complaining about the lack of background wallpaper rotation since “feh” doens’t work under it.

  • @fernandomaroto Well, you could try to do something like that, but crontab and Linux go way back together, and crontab doesn’t use much in the way of resources. It’s just always there in the background. It’s the way things are done!

    There are other desktop environments you could try. Xfce and Mate both support multiple workspspace desktops and you can have rotating wallpapers independently on each of the workspaces.

  • @shwaybotx said in Tutorial: Automatically rotate Gnome Wallpaper:

    Step 4: start cron
    Open a terminal, log on as root, and start cron. Don’t use sudo for this. Login with su.

    I’ve found a problem with my own tutorial. This changes my wallpaper VERY nicely! But it doesn’t “stick”. After I reboot, I have to go to a terminal and enter:

    sudo cron start

    … every time. I have yet to figure out how to get my system to do that automatically before I log into Gnome. I’ve been thoroughly confused by reading Wikis about systemd. I’m resolved at this point to have to enter the command manually every time I reboot my computer.

  • @shwaybotx Do you really need the sudo?
    if not you can look into something like “autostart or startup config” (not sure how it looks like under Gnome) probably in Central Configurations and then just run cron.
    I’ll login into a Gnome and get back to you.

  • @fernandomaroto said in Tutorial: Automatically rotate Gnome Wallpaper:

    I’ll login into a Gnome and get back to you.

    I’ve got it figured out. I now leave cron out of the picture altogether and use systemcltd - the Antergos way. I’ll post a new tutorial about it to document how I achieved it. But the new way will keep the wallpapers changing even after rebooting. Here’s the new method that I just posted.

gnome361 automatically13 tutorial4 rotate3 Posts 8Views 1544
Log in to reply
Bloom Email Optin Plugin

Looks like your connection to Antergos Community Forum was lost, please wait while we try to reconnect.