The joy of hacking : screensaver’s prefs

It so happens that I need to change the settings of the System Preferences’ Screen Saver pane, programmatically. I need to make the slide show one non-random.

Armed by nothing more than my trusty Cocoa Documentation and my guile, I try to see where the preference is stored. It’s in the ByHost section of the defaults, and changing it apparently does nothing.

Programmatically, changing the default for another application generally means using

ScreenSaverDefaults *prefs = [ScreenSaverDefaults defaultsForModuleWithName:@""];
[prefs setBool:NO forKey:@"Random"];
[prefs synchronize];

But it doesn’t work. So I scratch my head long and hard. I try subclassing, I try changing it through gdb. I try a lot of things.

Finally, it comes in a flash : the slide show preferences, for some obscure reason, seem to be attached (at least on a temporary basis) to [ScreenSaverDefaults defaultsForModuleWithName:[NSString stringWithFormat:@"", [directory lastPathComponent]]] !

Illogical? Maybe. But it works :)



Leave a Reply