Nicole Stein
Nicole Stein

Reputation: 925

Fade Desktop Wallpaper in Applescript (Mac OS X)

I have written an AppleScript which, among other things, sets my desktop background. However, using AppleScript's "set picture" changes the background abruptly - it doesn't look too good. Is there a way to get the nice fade effect that is used when you cycle the background via the Desktop & Screen Saver preferences' "Change Picture" setting?

Ideally, I'd like to do this in AppleScript, but if it's possible in Cocoa (or something else), please do let me know! Thanks!

Upvotes: 0

Views: 1293

Answers (2)

Fabrizio Giudici
Fabrizio Giudici

Reputation: 532

The original question is more than ten years old, but I suppose it still makes sense to post another contribution — after all I ran into this article because I was searching for it.

After playing with AppleScript I wasn't able to find any satisfactory solution. So I used an alternate approach: let the system do its job as usual without tweaking with it, but changing the images it manages on the fly.

In other words: assuming that $TEMP_WALLPAPER_FOLDER is an empty working folder, I configured System Preferences to use it as the folder with background pictures, I disabled random order and set to change background every 5 seconds.

Then this little piece of bash script, called every five minutes, does the job. Assuming that $IMAGE is the new image to use:

  1. It links $IMAGE to the temporary folder with a link whose name is the current timestamp (it isn't necessary to have a timestamp, a progressive index would do, but a timestamp is easier to manage); at this point there are two links in the folder, the previous image and the new one.
  2. It waits for 8 seconds: in this way we are sure that a 5-seconds change happens, so the system finds the new image and switches to it; and that it happens only once, so it doesn't switch again, back to the previous image.
  3. It removes the link to the previous image; now there is again only one link in the folder, so when the 5-seconds period expires again the system finds only the current image. I assume that the system is smart enough not to waste CPU in this circumstance, that is it doesn't start a fade transition to the same image.
        TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
        ln -fs "$IMAGE" "$TEMP_WALLPAPER_FOLDER/$TIMESTAMP.jpg"
        sleep 8
        find "$TEMP_WALLPAPER_FOLDER" -type l | grep -v "$TIMESTAMP" | xargs rm

Upvotes: 0

Nicole Stein
Nicole Stein

Reputation: 925

Answering my own question!

It's not exactly what I was looking for, but close enough:

set picture rotation to 1 -- turn on wallpaper cycling
set change interval to -1 -- force a change to happen right now
delay 1.5 -- wait a bit to allow for the fade transition - you may want to play w/ this #
set picture of item N of theDesktops to POSIX file ("yourfilenamehere.png") -- set wallpaper to wallpaper you want
set picture rotation to 0  -- turn off wallpaper cycling

By taking advantage of Apple's built-in wallpaper changer, you can get the fade effect in AppleScript, but you'll need to put whatever images you want to change between in a directory together and select it either in the Desktop & Screen Saver preferences or programmatically.

Also, set picture rotation to 1 seems to automatically change the wallpaper to what I think is the first image (alphabetically) in that directory - I didn't bother to test this, though, it didn't matter for my purposes. The delay of 1.5 allows for a bit of blinking, but since the image I was using was a TARDIS, that's acceptable and actually made for a cool effect (so long as we watch out for weeping angels!)

Upvotes: 1

Related Questions