Detecting lock screen on Mac through Python3
问题 Trying to find a way to detect if the screen is locked on a Mac system, using Python3 I've tried the following, and it gives a KeyError: import Quartz gui_dict = Quartz.CGSessionCopyCurrentDictionary() print(gui_dict['CGSSessionScreenIsLocked']) edit: import Quartz all_windows = Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID) for x in all_windows: if x["kCGWindowOwnerName"] == "loginwindow" print("Locked!") This code works on Python2, but not