diff power_osx.py @ 3:3d7fc94a404a

a few more inputs; daemonize
author drewp@bigasterisk.com
date Wed, 08 Mar 2023 10:57:11 -0800
parents 0ecb388a0b90
children
line wrap: on
line diff
--- a/power_osx.py	Sat Mar 04 12:10:36 2023 -0800
+++ b/power_osx.py	Wed Mar 08 10:57:11 2023 -0800
@@ -1,10 +1,18 @@
 import subprocess
-import Quartz
+import ast
+
 
 def is_screen_on():
-    d=Quartz.CGSessionCopyCurrentDictionary()
-    print(d)
-
+    screen_is_locked = ast.literal_eval(
+        subprocess.check_output(
+            [
+                '/usr/bin/python',  # system one with Quartz available
+                '-sc',
+                'import Quartz; ' +
+                'print Quartz.CGSessionCopyCurrentDictionary().get("CGSSessionScreenIsLocked", False)'
+            ],
+            encoding='ascii'))
+    return not screen_is_locked
 
 
 def go_lock_screen():
@@ -18,4 +26,5 @@
 def go_sleep_mode():
     subprocess.run(['pmset', 'sleepnow'])
 
+
 is_screen_on()
\ No newline at end of file