I've made a custom directory where I've put a couple of my favourite wallpapers. I made a script which examines this directory, counts the number of PNGs, and then randomly sets one image as a wallpaper. It looks like this:
#!/bin/bash
#number of images in wallpaper folder
cd $HOME/Favourite\ wallpapers/
numImages=`ls *.png | wc -l`
#randomly chose one number
randomNum=$[ ( $RANDOM % $numImages ) + 1 ]
#command to set wallpaper
gsettings set org.gnome.desktop.background picture-uri file://$HOME/Favourite\ wallpapers/00$randomNum.png
Now, how can I make this script runs on each login (this is very easy thou) or once a day if not has been already run on login?
The problem is that I often suspend my Ubuntu and then awake it tomorrow morning, so in this case I never log in again. Setting this script as startup job would not help me as, obviously, when awaken from suspend, I never re-log in. I cannot simply set it via cron
job as well because in cases when I do log in, the wallpaper would be changed two times a day.
PS. anyone feel free to use this script with cron
(just set your own path and filename template or wait for a solution like mine :)
.bashrc
and your user-specificcrontab
, and have the scripttouch
a file in/tmp
every time it runs, then checking how much time it has passed before it runs again. However, you wallpaper won't change if you aren't logged in at the time when the cron job is scheduled, which might make it necessary to schedule to job withanacron
instead. And the length of the above sentence should indicate that you might be better off adopting one of the few available wallpaper rotation applications.