Search code examples
pythonobjective-cmacososx-elcapitanpyobjc

Python code to detect dark mode in OS X El Capitan to change the status bar menu icon


I have objective C code to detect dark mode to change the status bar:

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

Similarly, how can we do the same in python?


Solution

  • Try these following lines wherever you want to detect the mode (dark mode or light mode).

    center = NSDistributedNotificationCenter.defaultCenter()
    center.addObserver_selector_name_object_(self,"enableDarkMode",'AppleInterfaceThemeChangedNotification',None)