1

I am trying to run a python script to download an image and change the desktop background all through one script. The download the image part if fine, but I'm having trouble actually changing the wallpaper with python. I am trying to use this command but it doesn't actually work. Below is my attempt

subprocess.call(["defaults", "write", "com.apple.Desktop", "background", 'default=/Users/pathtomyname/img.jpg'])


    SCRIPT = """/usr/bin/osascript<<END
tell application "Finder"
set desktop picture to POSIX file "%s"
end tell
END"""

def set_desktop_background(filename):
    subprocess.Popen(SCRIPT%filename, shell=True)
user1987920
  • 165
  • 1
  • 1
  • 8
  • Possible Duplicate http://stackoverflow.com/questions/431205/how-can-i-programatically-change-the-background-in-mac-os-x – halex Mar 18 '13 at 08:08
  • Not a duplicate, I read that link. Thats where I got the subprocess idea from, but I couldn't figure out how to implement the subprocess idea from the one comment on that page. The rest of the comments say to use applescript which is not even updated anymore. – user1987920 Mar 18 '13 at 08:52
  • What's wrong with the example using subprocess and osascript? Because it works perfectly. – robertklep Mar 18 '13 at 09:38
  • I tried using the exact script the one comment listed (which I edited into my code above) but I am getting the error: Finder got an error: AppleEvent handler failed. (-10000). Do you know why? – user1987920 Mar 18 '13 at 17:27

0 Answers0