How to get and set the wallpaper in objective c on Mac OSX?
I am looking for a way t开发者_高级运维o get (and set) the wallpaper in objective c under Mac OS X.
Do you have code/pointer for this?
Thanks in advance for your help.
For OSX >= 10.6 use NSWorkSpace
:
-desktopImageURLForScreen:
-setDesktopImageURL:forScreen:options:error:
For a CFPreferences
-based solution see e.g. the topdraw sources:
CFStringRef appID = CFSTR("com.apple.desktop");
CFStringRef bkg = CFSTR("Background");
// get:
NSDictionary *origBackgroundDict = (NSDictionary)CFPreferencesCopyAppValue(bkg, appID);
// ...
// set and notify dock:
CFPreferencesSetAppValue(bkg, (CFPropertyListRef)backgroundDict, appID);
CFPreferencesAppSynchronize(appID);
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:@"com.apple.desktop" object:@"BackgroundChanged"];
精彩评论