Well, this is a bit of a script I wrote one year ago or so: I wanted to have the feature of rotating wallpapers back in GNOME 3.x (I’m pretty sure it existed back in GNOME 2.x! š ), hence I wrote a bit of Python that reads a list of images in a given folder, randomly picks one and sets it as the desktop wallpaper – pretty simple stuff!
[sourcecode language=”python” wraplines=”true”]#!/usr/bin/python
import os
import random
import mimetypes
import time
myBackgrounds = ‘~/wallpapers/’
def prepareList(pathname):
items = []
for item in os.listdir(myBackgrounds):
if "image" in mimetypes.guess_type(item)[0]:
items.append(item)
return items
def randomizeWallpaper(listOfFiles):
randomListIndex = random.randint(0,len(listOfFiles)-1)
#~ os.system(‘gsettings set org.gnome.desktop.background picture-uri "file:///’ + myBackgrounds + listOfFiles[randomListIndex] + ‘"’ ) # for GNOME session
os.system(‘xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s %s’ % (myBackgrounds + listOfFiles[randomListIndex])) # for Xfce WM
if __name__ == "__main__":
listOfWallpapers = prepareList(myBackgrounds)
randomizeWallpaper(listOfWallpapers)
[/sourcecode]
In order to keep it running automatically every # of hours, I’ve just edited my crontab file (/etc/crontab) to run it periodically (in the case below it is configured to run every 6 hours…):
[sourcecode language=”text”]
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
0 */6 * * * manuel DISPLAY=:0.0 /home/manuel/bin/rotate-wallpapers.py > /dev/null
[/sourcecode]
And since my dynamic wallpaper folder is synced with Dropbox, I can have the same wallpapers in every computer I have access to (even – gah – Windows machines!). Furthermore, I also have all my wallpapers on my Android phone, courtesy of DropSync (which pulls the images from Dropbox whenever there’s a change in there and downloads them to a folder on my memory card) and a dynamic wallpaper thingy called Wallpaper Slideshow. Both are free of charge at the Play Store, and the latter is extremely configurable!
A final note regarding my collection of wallpapers: all of them are photos I took, I want them to remind me of places I’ve been to… and places where I want to be! š It really brightens my day whenever I see a lovely photo of River Douro on my work desktop, for instance… š
Comments
January 26, 2013 17:33
January 26, 2013 20:32