Ich habe versucht, die genau die gleiche Sache zu tun. Sie können die aktuelle Desktop-Bild-URL erhalten:
- Abrufen der aktuellen Raum UUID aus der com.apple.spaces Eigenschaftsliste,
- die com.apple.desktop Eigenschaftsliste für den passenden Raum Suchen,
- die URL aus der Eigenschaft Name VZ Extrahierung
ich noch arbeiten daran, aber der folgende Code erhält die korrekte URL ... manchmal. Das Hauptproblem besteht darin, dass die Eigenschaftslisten nicht häufig genug aktualisiert werden und ich nicht in der Lage war, sie zu zwingen, zu erneuern (kurz, das Dock zu töten). Lass es mich wissen, wenn du etwas herausgefunden hast!
NSDictionary *spacesPLIST = (__bridge NSDictionary *)(CFPreferencesCopyAppValue(CFSTR("SpacesConfiguration"), CFSTR("com.apple.spaces")));
NSDictionary *desktopPLIST = (__bridge NSDictionary *)(CFPreferencesCopyAppValue(CFSTR("Background"), CFSTR("com.apple.desktop")));
NSArray *monitors = [spacesPLIST valueForKeyPath:@"Management Data.Monitors"];
NSInteger monitorIndex = 0;
if ([monitors count] > 1) {
//search for main (or ask user to select)
}
NSDictionary *monitor = [monitors objectAtIndex:monitorIndex];
NSDictionary *spaces = [desktopPLIST valueForKey:@"spaces"];
NSString *currentSpaceUUID = [monitor valueForKeyPath:@"Current Space.uuid"];
NSDictionary *currentSpace = [spaces valueForKey:currentSpaceUUID];
NSURL *desktopPicturesDirectory = [NSURL fileURLWithPath:[currentSpace valueForKeyPath:@"default.ChangePath"] isDirectory:true];
NSString *desktopPictureName = [currentSpace valueForKeyPath:@"default.LastName"];
NSURL *desktopPictureURL = [NSURL URLWithString:desktopPictureName relativeToURL:desktopPicturesDirectory];
[[NSWorkspace sharedWorkspace] selectFile:[desktopPictureURL path] inFileViewerRootedAtPath:@""];
Ich habe https://openradar.appspot.com/radar?id=5782854294306816 geöffnet, da es besser wäre, wenn die API tat, was sie verspricht. –