Setting the desktop background on all Spaces in Cocoa
如果用户想为多个空间设置桌面背景,请尝试以下代码:-
有关更多信息,请参阅此
NSString* path = @"/Users/abc/Desktop/yourImg.png";
NSUserDefaults* def = [NSUserDefaults standardUserDefaults];
NSMutableDictionary* desktopDict = [NSMutableDictionary dictionaryWithDictionary:[def persistentDomainForName:@"com.apple.desktop"]];
NSMutableDictionary* bgDict = [desktopDict objectForKey:@"Background"];
NSMutableDictionary* spaces = [bgDict objectForKey:@"spaces"];
[spaces enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSMutableDictionary* obj, BOOL *stop) {
[obj enumerateKeysAndObjectsUsingBlock:^(id key, NSMutableDictionary* prefs, BOOL *stop) {
[prefs setObject:path forKey:@"ImageFilePath"];
[prefs setObject:path forKey:@"NewImageFilePath"];
[prefs setObject:@"Never" forKey:@"Change"];
}];
}];
[def setPersistentDomain:desktopDict forName:@"com.apple.desktop"];