Set desktop pictures using AppleScript

May 08, '09 07:30:02AM

Contributed by: Anonymous

This hint was inspired by a study that found red wallpaper conducive to detail-oriented work, while blue wallpaper works better for creative work. Based on that, I wrote a simple AppleScript to display a dialog that allows the user to choose between working environments. The script then sets the desktop picture based on the user's selection.

Note that this hint assumes you've already created the new solid colors (very dark gray, very dark blue, and very dark red) as explained in this previous hint. Once you have those colors (or others, if you prefer; just change the script as necessary), create the following AppleScript:

set buttonList to {"Neutral", "Creative", "Detail"}
set colorList to {"Solid Gray Very Dark", "Solid Blue Very Dark", "Solid Red Very Dark"}
display dialog "Which environment?" buttons buttonList default button 1
set selectedButton to the button returned of the result

repeat with index from 1 to 3
  if item index of buttonList = selectedButton then exit repeat
end repeat

set selectedColor to item index of colorList

tell application "Finder"
  set desktop picture to {"Macintosh HD:Library:Desktop Pictures:Solid Colors:" & selectedColor & ".png"} as alias
end tell
[robg adds: I tested this, and it works as described. If you want to use more colors, you need to change both the buttonList and colorList lines so that they remain in sync. The list of colors in colorList must exactly match the colors' filenames as seen in the Finder.]

Comments (8)


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