Skip to content

Commit d95250b

Browse files
committed
use Quartz instead of osacript to detect locked screen on macos
Fixes #168
1 parent fb57d1a commit d95250b

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

ntfy/screensaver.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ def macos_detect():
9797

9898

9999
def macos_is_locked():
100-
# Strictly-speaking, this detects whether or not the screensaver is running. The screensaver
101-
# may or may not be locked.
102-
cmd = '''tell application "System Events"
103-
get running of screen saver preferences
104-
end tell'''
105-
return check_output([ 'osascript', '-e', cmd ]) == b'true\n'
100+
# https: // stackoverflow.com/questions/11505255/osx-check-if-the-screen-is-locked
101+
import Quartz
102+
d = Quartz.CGSessionCopyCurrentDictionary()
103+
screenIsLocked = d.get("CGSSessionScreenIsLocked", 0) == 1
104+
105+
return screenIsLocked
106106

107107

108108
def is_locked():

0 commit comments

Comments
 (0)