File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from shlex import split
22from subprocess import check_output , check_call , CalledProcessError , PIPE
3+ import sys
34
45# some adapted from
56# https://github.com/mtorromeo/xdg-utils/blob/master/scripts/xdg-screensaver.in#L540
@@ -91,6 +92,19 @@ def matescreensaver_is_locked():
9192 return bool (dbus_iface .GetActive ())
9293
9394
95+ def macos_detect ():
96+ return sys .platform == 'darwin'
97+
98+
99+ 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 '
106+
107+
94108def is_locked ():
95109 if xscreensaver_detect ():
96110 return xscreensaver_is_locked ()
@@ -100,4 +114,6 @@ def is_locked():
100114 return gnomescreensaver_is_locked ()
101115 if matescreensaver_detect ():
102116 return matescreensaver_is_locked ()
117+ if macos_detect ():
118+ return macos_is_locked ()
103119 return True
You can’t perform that action at this time.
0 commit comments