Created
September 10, 2011 22:45
-
-
Save bassdread/1208902 to your computer and use it in GitHub Desktop.
Python to change your desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess, sys, os | |
import os.path | |
import random | |
def octo_desktop(dirname): | |
"""Over see the swapping of the desktop""" | |
if os.path.isdir(dirname): | |
img_string = pick_image(dirname) | |
swap_image(os.path.join(dirname, img_string)) | |
def swap_image(filepath): | |
subprocess.call(['gconftool-2', '-s', '-t', 'string', '/desktop/gnome/background/picture_filename', filepath]) | |
def pick_image(path): | |
dir_list=os.listdir(path) | |
pics = [] | |
for fname in dir_list: | |
if fname.endswith('jpg') or fname.endswith('png'): | |
pics.append(fname) | |
return pics[random.randint(0,len(pics) -1)] | |
if __name__ == '__main__': | |
octo_desktop(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment