Skip to content

Commit

Permalink
use Quartz instead of osacript to detect locked screen on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwremmel committed Mar 22, 2018
1 parent fb57d1a commit d95250b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ntfy/screensaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ def macos_detect():


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

return screenIsLocked


def is_locked():
Expand Down

0 comments on commit d95250b

Please sign in to comment.