Search code examples
objective-cmacosnscolor

Detecting when macOS 10.14 accent color has changed


In macOS 10.14 you can detect when the system theme has changed by listening to the following notification:

[NSDistributedNotificationCenter.defaultCenter addObserver: self
                                                  selector: @selector(OSThemeChanged:)
                                                      name: @"AppleInterfaceThemeChangedNotification"
                                                    object: nil];

But this does not get fired when the Accent color changes (NSColor.controlAccentColor). I have an image I want to modify based on the accent color, so I would like to know when it changes.

Has anyone been able to figure this out?


Solution

  • AppleColorPreferencesChangedNotification key should work I believe:

        [[NSDistributedNotificationCenter defaultCenter] addObserver:self
                                                            selector:@selector(accentColorChanged:)
                                                                name:@"AppleColorPreferencesChangedNotification"
                                                              object:nil];
    

    Notification isn't sent until the preference is changed and the system preferences general window is closed.

    Couldn't find the documentation to link to for it though.