Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set desktop pictures using AppleScript Desktop
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: [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.]
    •    
  • Currently 1.88 / 5
  You rated: 3 / 5 (8 votes cast)
 
[14,776 views]  

Set desktop pictures using AppleScript | 8 comments | Create New Account
Click here to return to the 'Set desktop pictures using AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set desktop pictures using AppleScript
Authored by: thyvillageidiot on May 19, '09 06:53:42AM

I very much like this hint. However, I took it a step further and made the Tiger "Aqua" background as the variable instead of just boring solid colors. You'll need
[a href="http://img530.imageshack.us/img530/2777/aquared.jpg"aquared[/a] and will have to rename it to Aqua Red and drop it off in Macintosh HD:Library:Desktop Pictures.

Then use this modified code:
set buttonList to {"Neutral", "Creative", "Detail"}
set colorList to {"Aqua Graphite", "Aqua Blue", "Aqua Red"}
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:" & selectedColor & ".jpg"} as alias
end tell



[ Reply to This | # ]
Set desktop pictures using AppleScript
Authored by: gregarios on Jul 23, '09 09:45:13PM

Assuming someone had their Desktop Pictures set to rotate every 15 minutes, in order...

How would someone cause the pictures to rotate prematurely, via the command-line?

osascript -e 'tell application \"Finder\" ..... ?



[ Reply to This | # ]
Set desktop pictures using AppleScript
Authored by: wallybear on Jul 24, '09 08:17:06AM

It is sufficient to change one of the parameters.
I use the following script that change and then reset the random order parameter:

tell application "System Events"
tell current desktop
set random order to false
set random order to true
end tell
end tell

the only drawback is that it changes the desktop picture twice (one for the "false" setting and one for the "true"); at the moment I've not found other tricks that fix this glitch.



[ Reply to This | # ]
Set desktop pictures using AppleScript
Authored by: tedw on Jul 24, '09 08:58:38AM
if you just use "osascript -e 'tell application "System Events" to set picture of desktop 1 to new/picture/path' it will change the picture without doing anything else. this picture will change again at the next normal change time.

[ Reply to This | # ]
Set desktop pictures using AppleScript
Authored by: Ofiuco on Aug 26, '09 11:38:09AM

I feel extremely dumb, but when I try to run just the desktop-picture changing part of this code (in the hopes of creating an applescript file I can call from elsewhere), like so:

tell application "Finder"
set desktop picture to file "~/the/exact/location/of/my/file.jpg"
end tell

I get 'Error: Finder can't set desktop picture to blah blah blah'. Changing 'desktop picture' to 'wallpaper' only gives me 'Error: can't get file blah blah'. Removing 'file' causes Script Editor to echo back the file path to me, which is funny only the first time.

Can you clue me in to what I'm doing wrong here?



[ Reply to This | # ]
Set desktop pictures using AppleScript
Authored by: tedw on Aug 26, '09 03:32:07PM
I feel extremely dumb, but when I try to run just the desktop-picture changing part of this code (in the hopes of creating an applescript file I can call from elsewhere), like so: tell application "Finder" set desktop picture to file "~/the/exact/location/of/my/file.jpg" end tell I get 'Error: Finder can't set desktop picture to blah blah blah'.
don't use unix file pointers. they work sometimes in the Finder, but not reliably. use Mac (colon-delimited) pointers. try HD:Users:yourname:location:of:file.

[ Reply to This | # ]
Set desktop pictures using AppleScript
Authored by: Ofiuco on Aug 26, '09 03:54:35PM

I also tried that; it does the same thing (echoes back the path of the file instead of actually doing anything).



[ Reply to This | # ]
Set desktop pictures using AppleScript
Authored by: tedw on Aug 26, '09 04:40:55PM
well, in that case I suggest you shift gears. If you look at the Finder's scripting dictionary, you'll see that desktop picture is part of the Legacy suite. The Apple preferred way to do this nowadays is to use System Events, as (for example):
tell application "System Events"
	set picture of every desktop to file "path:to:picture"
end tell
(note that if you're using a rotating pictures setup, this will work, but the change won't be visible until you turn picture rotation off)

[ Reply to This | # ]