UncategorizedDynamic wallpapers in a GNU/Linux desktop (or, for the record, anywhere!…)

Dynamic wallpapers in a GNU/Linux desktop (or, for the record, anywhere!…)

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… šŸ˜‰

Categories: Uncategorized Tags: , , ,

Comments

  1. Rui Gouveia

    January 26, 2013 17:33

    Hi, Awesome!!!! :) Some sugestions: 1. Create an extensions for Gnome3 and share it in https://extensions.gnome.org/ 2. Allow some form of configuration, so you can define more than one folder. 3. Install the cronjob in the user crontab instead of the system crontab. See "$ crontab --help" to start. Nice Work! Cheers, Rui
    1. manuel

      January 26, 2013 20:32

      Hello, thanks for the feedback! :) Currently I'm running it with Xfce, I've given GNOME 3 a break and I am testing whether I can "live" with a lighter desktop environment. But yeah, I'll try to see if I can make the script read an external list of folders, and I'm also going to put it in the user crontab - it is a bit overkill to have it in the system one! ;) Thanks again, MM

Reply to manuel cancel

Your email address will not be published. Required fields are marked *