desktop picture
desktop picture
- Subject: desktop picture
- From: email@hidden
- Date: Wed, 22 May 2002 11:49:59 -0700
I *really* hate to ask this again...
but I've looked through the archives and found several different ways to
do this, but none of them work any more.
How do you change the desktop picture dynamically from a Cocoa program?
I've found two references, one a program called ChangeDesktop, which is
a stunning 7,610 lines of code, seems to use tons and tons of
Carbon/AppleEvents code... which I could neither decipher, nor make work
in my cocoa app.
The second was RandomBackground, which seems to work, but it only
changes things at login.
I want to change the background picture and have it reflected
immediately.
The code I have now properly updates com.apple.desktop's defaults... but
it seems that the notification is ignored by finder.
Can anyone see what's wrong with my code?
I'm on 10.1.4 (5Q25)
- (void)setDesktopPicture:(id)path
{
id desktop = [[[NSUserDefaults standardUserDefaults]
persistentDomainForName:@"com.apple.desktop"] mutableCopy];
id background = [[desktop objectForKey:@"Background"] mutableCopy];
int i, n = [background count];
id displayIDs = [background allKeys];
for (i = 0; i < n; i++) {
id did = [displayIDs objectAtIndex:i];
id display = [[background objectForKey:did] mutableCopy];
[display setObject: path forKey:@"ImageFilePath"];
[display setObject:@"Crop" forKey:@"Placement"];
[background setObject:display forKey:did];
}
[desktop setObject:background forKey:@"Background"];
[[NSUserDefaults standardUserDefaults] setPersistentDomain:desktop
forName:@"com.apple.desktop"];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"com.apple.desktop" object:@"BackgroundChanged"];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.