Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get and set the wallpaper in objective c on Mac OSX?

I am looking for a way to 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.

like image 608
AP. Avatar asked Jul 10 '10 18:07

AP.


People also ask

Where does OSX store wallpaper?

Open the System Preferences app. Click on Desktop & Screen Saver. Double click on "Desktop Pictures" on the left side to open the Desktop Pictures folder. Click into this folder when it opens up (alternatively, go to System > Library > Desktop Pictures).


1 Answers

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"];
like image 109
Georg Fritzsche Avatar answered Nov 18 '22 06:11

Georg Fritzsche