Periodically changing wallpaper under GNOME 3?

Save the following shell script somewhere:

#!/bin/bash

WP_DIR=/home/honeyp0t/wallpapers

cd $WP_DIR
while [ 1 ] 
  do
  set -- * 
  length=$#
  random_num=$((( $RANDOM % ($length) ) + 1)) 

  gsettings set org.gnome.desktop.background picture-uri "file://$WP_DIR/${!random_num}"

  sleep 600 
done

Then in your home directory in .config/autostart put the following into a file called wallpaper-changer.desktop

[Desktop Entry]
Name=wallpaper-changer
Exec=/home/sammhe/bin/setbg.sh
Comment=change wallpaper every so often
Hidden=false
Type=Application
X-GNOME-Autostart-enabled=true

This will change your wallpaper every 10 minutes… or whatever value you set in the script…

I originally posted this as a comment on a post entitled "Customizing the GNOME Shell" at Musings of an OS plumber.


This is the solution you are looking for:

  • http://dsathe.blogspot.com/2011/06/auto-background-changer-for-gnome-3-gui.html
  • http://www.omgubuntu.co.uk/2011/06/wallpaper-slideshow-app-for-gnome-3/

I made it; just a testing version but works!


If you'd prefer to use a cron job instead of an init script, here's what I did. Thanks to Hubert for inspiration!

#!/bin/bash

walls_dir=$HOME/.wallpapers
selection=$(find $walls_dir -type f -name "*.jpg" -o -name "*.png" | shuf -n1)
gsettings set org.gnome.desktop.background picture-uri "file://$selection"

Save the script somewhere (e.g. $HOME/bin/rotate_bg), make it executable (chmod +x $HOME/bin/rotate_bg), then add the cron job to run it as often as you want your background to change. Run crontab -e to edit the cron table for your user. Here is a link describing the crontab format. The following entry will rotate your background every 10 minutes:

*0 * * * * $HOME/bin/rotate_bg