15

I use Fedora 15 with GNOME 3 and I'd like my wallpaper to periodically change like it's possible with Windows 7. It would be the best if it could use RSS/Atom or a specified directory.

I haven't found any tools in the repository. I guess you can change it with a script and cron, but I'm looking for something more elegant.

fixer1234
  • 27,064
  • 61
  • 75
  • 116
KovBal
  • 1,250
  • 1
  • 13
  • 24

6 Answers6

19

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.

slhck
  • 223,558
  • 70
  • 607
  • 592
Hubert Samm
  • 191
  • 2
  • I can't find anything about changing wallpaper or Hubert Samm on your link. Could you be more specific? – KovBal Jun 16 '11 at 19:59
  • Or you can just write it down here :) (I didn't checked your name, sorry :)) – KovBal Jun 16 '11 at 20:00
  • 1
    It's worth noting that you might also want to set the `pictures-options`: `gsettings set org.gnome.desktop.background picture-options ''` – Daniel Quinn Jul 02 '12 at 14:26
  • this doesn't work for gnome 2 right? – Vicfred Mar 26 '13 at 01:33
  • What "set -- *" does exactly? – SergioAraujo Dec 30 '13 at 17:56
  • Thanks! I made it work a bit different: the .desktop file is not needed just call `gnome-session-properties` and add the first .sh scrip to your startup applications, also I needed to set `gsettings set org.gnome.desktop.background show-desktop-icons true` to make the change show on the desktop `gsettings set org.gnome.desktop.background picture-options 'zoom'` for the pictures to look nice. – select Nov 16 '14 at 21:18
  • @SergioAraujo This is a unix trick I rarely see. `set -- *` is pretty neat. `set -- ...` just sets the $1, $2, etc. vars to the list you pass it, as well as `$#` to the count of those things. So `set -- *` is a quick way to count files. `*` lists the files, and `set --` sets that list to the dollar vars, and the length var `$#` – Michael Campbell Oct 13 '18 at 18:33
6

This is the solution you are looking for:

I made it; just a testing version but works!

Gaff
  • 18,569
  • 15
  • 57
  • 68
3

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
Nathan Wallace
  • 196
  • 2
  • 6
  • You are uncorrect here. [Sleep](http://en.wikipedia.org/wiki/Sleep_(Unix)) is not a busy wait – Art Gertner May 26 '14 at 20:46
  • if you got a citation i'll change my answer – Nathan Wallace May 26 '14 at 20:55
  • from the same source that I have linked above: `The sleep instruction suspends the calling process for at least the specified number of seconds (the default), minutes, hours or days`. E.g. process does not get called and does not waste CPU cycles. Also from [Busy Waiting on Wiki](http://en.wikipedia.org/wiki/Busy_waiting) : `Busy-waiting itself can be made much less wasteful by using a delay function (e.g., sleep()) found in most operating systems. This puts a thread to sleep for a specified time, during which the thread will waste no CPU time` – Art Gertner May 26 '14 at 21:00
1

For some reason, I can't see a way to reply to Hubert Samm, but I found his link helpful. Just in case it goes down or you don't want to read the whole thing to get this particular answer, I've added how I managed to accomplish a live-updating background in Gnome 3.

By going to ~/.cache/gnome-control/center/backgrounds you will find a file with a long name (something like "a4f327082b43572cfa36ad23b5e1fda7be77b6fb6bfe362e4d682fd9c6699f27" ) which is the cached version of the file you have set your background to. If you delete this file and create a symlink with the same name to replace it:

$ rm a4f327082b43572cfa36ad23b5e1fda7be77b6fb6bfe362e4d682fd9c6699f27 
$ ln -s /path/to/original/file a4f327082b43572cfa36ad23b5e1fda7be77b6fb6bfe362e4d682fd9c6699f27

then, as the original file is updated, the desktop background will change to reflect that. I am using this technique to make sure my XPlanetFX background stays up to date. For example, simply have an image called "background.jpg" and change this file whenever you wanted to update the background.

Probably the more correct way to go about this would be to use gsettings to change the picture-uri address to point directly to the file of your choosing, but I chose the symlink option because I didn't know how persistent the setting change would be when using the UI to change the wallpaper. Either way should work in theory, however.

Note: I don't know this for sure as I didn't test it, but there's a good chance that if you change your background through the normal UI, that long unique filename will change, and your symlink will not be useful any longer.

Adam
  • 11
  • 1
1

Save the following shell script somewhere:

#!/bin/bash
while true; do
file=`/bin/ls -1 $1 | sort --random-sort | head -1`;path=`readlink --canonicalize "$dir/$file"`;
gsettings set org.gnome.desktop.background picture-uri "file://"$1$path;sleep $2;done

Run it using the syntax:

scriptname directoryofpictures howmanyseconds
I say Reinstate Monica
  • 25,487
  • 19
  • 95
  • 131
Brainz
  • 11
  • 1
0

Several answers involve using picture-uri key from org.gnome.desktop.background schema. It is worth mentioning that gnome now has a dark mode for which picture-uri-dark should be used instead.

$ gsettings list-keys org.gnome.desktop.background
color-shading-type
picture-opacity
picture-options
picture-uri
picture-uri-dark
primary-color
secondary-color
show-desktop-icons

Actually, it was also described in https://askubuntu.com/questions/1403952/wallpaper-background-switches-back-to-default-when-in-dark-mode-22-04-lts

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 14 '22 at 11:02