Change desktop picture without Finder restart

Aug 19, '10 07:30:00AM

Contributed by: tedw

This is a revision of an 8 year old hint - listed here - on how to update the desktop picture from a downloaded image.

Things have moved on a bit from 2002, but since at least one person is still interested in this hint, here's a revised version for 10.5.x and 10.6.x.

There are three changes:

The Script (test image courtesy of XKCD Comics):
set pictureURL to "http://imgs.xkcd.com/comics/barrel_cropped_(1).jpg"
set localFile to POSIX path of (path to home folder from user domain) & "DTPic.jpg"
set cmd to "curl " & quoted form of pictureURL & " > " & quoted form of localFile
do shell script cmd

tell application "System Events"
  tell desktop 1
    set picture rotation to 1
    set picture rotation to "never"
    set picture to POSIX file localFile
  end tell
end tell
The image should be automatically scaled to fit. If the image is an odd size and suffers distortion, you can add in a call to Image Events (before the call to System Events) to size it correctly:
tell application "Image Events"
  set theImage to open localFile
  scale theImage to size 1200 -- adjusts the longest edge (assumedly the bottom edge) to a reasonable size
  pad theImage to dimensions {1440, 900} -- pads the image with black to the size of the screen to prevent distortion
  save theImage
end tell
Save this as a script and run it from the script menu, or from launchd using osascript if you want to change the image at scheduled times.

[crarko adds: I tested this, and it works as described.]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20100817143748402