File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,12 +97,24 @@ def macos_detect():
9797
9898
9999def macos_is_locked ():
100- # Strictly-speaking, this detects whether or not the screensaver is running. The screensaver
100+ # Strictly-speaking, this detects whether or not the screensaver is running. The screensaver
101101 # may or may not be locked.
102102 cmd = '''tell application "System Events"
103103 get running of screen saver preferences
104104 end tell'''
105- return check_output ([ 'osascript' , '-e' , cmd ]) == b'true\n '
105+ screensaver_is_running = check_output (
106+ ['osascript' , '-e' , cmd ]) == b'true\n '
107+ if screensaver_is_running :
108+ return True
109+
110+ # The screen may be locked even if the scrensaver is not running. This
111+ # *should* cover that scenario.
112+ # https: // stackoverflow.com/questions/11505255/osx-check-if-the-screen-is-locked
113+ import Quartz
114+ d = Quartz .CGSessionCopyCurrentDictionary ()
115+ screen_is_locked = d .get ("CGSSessionScreenIsLocked" , 0 ) == 1
116+
117+ return screen_is_locked
106118
107119
108120def is_locked ():
You can’t perform that action at this time.
0 commit comments