Skip to content

Instantly share code, notes, and snippets.

@AndrewWCarson
Created March 29, 2019 23:05
Show Gist options
  • Save AndrewWCarson/fdd324c4a5ccaf7e5d3e25d8f9959bd0 to your computer and use it in GitHub Desktop.
Save AndrewWCarson/fdd324c4a5ccaf7e5d3e25d8f9959bd0 to your computer and use it in GitHub Desktop.
Toggle between Light & Dark mode.
#!/usr/bin/python
#
# This toggles the macOS appearance from Light mode to Dark mode and vice
# versa.
#
# Big thanks to Mike Lynn for his help. Esp. this gist:
# https://gist.github.com/pudquick/ba235b7e90aafb9986158697a457a0d0
#
# Still looking for the function to perfectly simulate changing themes via the
# System Prefs UI. iStat menus seems to not be getting the hint.
import platform
from Foundation import NSBundle
vers, _, _ = platform.mac_ver()
if float(vers.split('.')[1]) != 14:
exit
else:
appearanceBundle = NSBundle.bundleWithPath_("/System/Library/PreferencePanes/Appearance.prefPane")
appearanceShared = appearanceBundle.classNamed_('AppearanceShared')
app = appearanceShared.sharedAppearanceAccess()
if app.theme() == 1:
app.setTheme_(0)
else:
app.setTheme_(1)
@AndrewWCarson
Copy link
Author

Doesn't notify apps when run from a different user context. Even sudo -u "$username from the root user doesn't send the notification to apps.
Yeah. This is a decent start, but needs some fluff for EUX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment