开发者

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"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜