Skip to content

Instantly share code, notes, and snippets.

@t-lark
Created August 8, 2020 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-lark/2eca6e625f740544975122d3615079d6 to your computer and use it in GitHub Desktop.
Save t-lark/2eca6e625f740544975122d3615079d6 to your computer and use it in GitHub Desktop.
detect dark, light, or auto mode
>>> from SystemConfiguration import SCDynamicStoreCopyConsoleUser
>>> from CoreFoundation import CFPreferencesCopyAppValue
>>> from Foundation import NSHomeDirectoryForUser
>>>
>>> user, uid, gid = SCDynamicStoreCopyConsoleUser(None, None, None)
>>> home = NSHomeDirectoryForUser(user)
>>> userfile = home + '/Library/Preferences/.GlobalPreferences.plist'
>>> keys = ['AppleInterfaceStyle', 'AppleInterfaceStyleSwitchesAutomatically']
# just loop and see what we get
>>> for k in keys:
... print(CFPreferencesCopyAppValue(k, userfile))
...
Dark
None
>>>
# test for None values
>>> for k in keys:
... result = CFPreferencesCopyAppValue(k, userfile)
... if result is not None:
... print(result)
...
Dark
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment