Ryan Knopp
Ryan Knopp

Reputation: 612

How to create cross-fade transition on OSX desktop wallpaper programmatically

I know how to set the desktop wallpaper by using setDesktopImageURL. However I'm trying to figure out how to do the cross-fade that OSX does when it switches wallpaper. Is there some sort of middle image trick I need to use or an animation trick? Image1 -> animation -> image2.

Any help would be welcome,

Thanks!

Upvotes: 2

Views: 789

Answers (2)

Daij-Djan
Daij-Djan

Reputation: 50119

their is no such function in cocoa

You can come close with a custom NSWindow you fade out or you use vash's applescript way which looks like a 'nice' workaround.

Upvotes: 0

vash
vash

Reputation: 52

For what I can tell there's no way of doing this whit Objective c. I've achieved this effect using osascript in my app. It's just a work around, it's limited and really far from perfection but it works for me.

Practically you have to use the fading effect already available in osx. To do so you must:
- put the image you want as wallpaper in a folder (only 1 image)
- set that folder as the source for your desktop wallpapers
- set the preferences to automatically switch the wallpapers

When you want to change the image you had to programmatically add it in the folder and remove the old one. The OS will fade it for you.

To set the folder:

system("osascript -e 'Tell application \"System Events\" to set pictures folder of current desktop to path/to/folder '")  

To set the automatic switch:

system("osascript -e 'Tell application \"System Events\" to set picture rotation of current desktop to 1'")

you can even set a delay in your app to wait for the images to switch and then call the last script to set the rotation to 0 (to disable it), but sometimes this will change your desktop to the default osx wallpaper (can't figure out why).

As I told you this is just a messy work around but maybe it could be of some help.

Upvotes: 3

Related Questions