Created
November 7, 2020 16:20
-
-
Save nikolay-n/10a45999eeebb10eadaedcda8069b5a3 to your computer and use it in GitHub Desktop.
Get/Set brightness macOS 10.13+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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