Skip to content

Instantly share code, notes, and snippets.

@nikolay-n
Created November 7, 2020 16:20
Show Gist options
  • Save nikolay-n/10a45999eeebb10eadaedcda8069b5a3 to your computer and use it in GitHub Desktop.
Save nikolay-n/10a45999eeebb10eadaedcda8069b5a3 to your computer and use it in GitHub Desktop.
Get/Set brightness macOS 10.13+
#!/usr/bin/python
from ctypes import CDLL, c_int, c_double
from Quartz import CGMainDisplayID
main_display_id = CGMainDisplayID()
CoreDisplay = CDLL("/System/Library/Frameworks/CoreDisplay.framework/CoreDisplay")
CoreDisplay.CoreDisplay_Display_SetUserBrightness.argtypes = [c_int, c_double]
CoreDisplay.CoreDisplay_Display_GetUserBrightness.argtypes = [c_int]
CoreDisplay.CoreDisplay_Display_GetUserBrightness.restype = c_double
def set_brightness(disp_id, value):
brightness /= 100
return CoreDisplay.CoreDisplay_Display_SetUserBrightness(disp_id, brightness)
def get_brightness(disp_id):
value = CoreDisplay.CoreDisplay_Display_GetUserBrightness(disp_id)
return round(value * 100, 2)
print(get_brightness(main_display_id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment