Python code for detecting dark mode in OS X El Capitan to change the status menu icon

I have C object code for detecting 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?

+1
source share
3 answers

Try the following lines, wherever you find the mode (dark or light mode).

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

I don't know if you can do this directly from within python. But at least you can call the terminal command defaults read -g AppleInterfaceStyle.

: 0, " ". 1 (), . , , Java-.

python - , .

+1

Python os .

, python , AppleInterfaceStyle .

import os

has_interface = os.popen("defaults find AppleInterfaceStyle").read()
if not has_interface:
    print("Use a light Style")
else:
    interface_system = os.popen("defaults read -g AppleInterfaceStyle").read()
    print("Interface Style:" + interface_system) # interface_system = 'Dark\n'
0

Source: https://habr.com/ru/post/1614140/


All Articles