ArunWiki : BackgroundUpdater

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Have a lot of background pictures, and get bored of your's really quick? Try this simple python script. It will update your background every timeout seconds, and pull pictures from pic_dir. I recommend ypu add it to your GNOME session (System -> Preferences -> Session).

Note: Works only on GNOME

background-changer.py
#!/usr/bin/env python
# Changes backgrounds every 1/2 hour

import os

timeout = 360 # 10 minutes
pic_dir = "/home/teju/config/Backgrounds/"
pic_extns = ["png","jpg","svg"]

cmd = "gconftool-2"
cmd_args = ["","-s","/desktop/gnome/background/picture_filename", "--type=str",]

def set_background (filename):
    args = cmd_args + [filename]
    return os.spawnvp (os.P_WAIT, cmd, args)

def get_file ():
    while True:
        for path, dirs, files in os.walk(pic_dir):
            for file in files:
                filename = str(file)
                extn = filename[filename.rfind('.')+1:]
                if extn in pic_extns:
                    #print filename
                    yield os.path.join (path, filename)
                else:
                    continue

if __name__ == "__main__":
    from gobject import MainLoop, timeout_add_seconds
    from random import randint
    gen = get_file()

    def change_background ():
        set_background (gen.next())
        return True

    # Start at a random file
    rand_seed = randint(1,100)
    for i in range (rand_seed):
            gen.next()
    change_background()

    loop = MainLoop()
    timeout_add_seconds (timeout, change_background)
    loop.run()

There is one comment on this page. [Display comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in -0.8619 seconds