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
@@ -94,6 +95,19 @@ def matescreensaver_is_locked():
9495 return bool (dbus_iface .GetActive ())
9596
9697
98+ def macos_detect ():
99+ return sys .platform == 'darwin'
100+
101+
102+ def macos_is_locked ():
103+ # Strictly-speaking, this detects whether or not the screensaver is running. The screensaver
104+ # may or may not be locked.
105+ cmd = '''tell application "System Events"
106+ get running of screen saver preferences
107+ end tell'''
108+ return check_output ([ 'osascript' , '-e' , cmd ]) == b'true\n '
109+
110+
97111def is_locked ():
98112 if xscreensaver_detect ():
99113 return xscreensaver_is_locked ()
@@ -103,4 +117,6 @@ def is_locked():
103117 return gnomescreensaver_is_locked ()
104118 if matescreensaver_detect ():
105119 return matescreensaver_is_locked ()
120+ if macos_detect ():
121+ return macos_is_locked ()
106122 return True
You can’t perform that action at this time.
0 commit comments