Mercurial > code > home > repos > racc
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:0ecb388a0b90 | 3:3d7fc94a404a |
---|---|
1 import subprocess | 1 import subprocess |
2 import Quartz | 2 import ast |
3 | |
3 | 4 |
4 def is_screen_on(): | 5 def is_screen_on(): |
5 d=Quartz.CGSessionCopyCurrentDictionary() | 6 screen_is_locked = ast.literal_eval( |
6 print(d) | 7 subprocess.check_output( |
7 | 8 [ |
9 '/usr/bin/python', # system one with Quartz available | |
10 '-sc', | |
11 'import Quartz; ' + | |
12 'print Quartz.CGSessionCopyCurrentDictionary().get("CGSSessionScreenIsLocked", False)' | |
13 ], | |
14 encoding='ascii')) | |
15 return not screen_is_locked | |
8 | 16 |
9 | 17 |
10 def go_lock_screen(): | 18 def go_lock_screen(): |
11 pass | 19 pass |
12 | 20 |
16 | 24 |
17 | 25 |
18 def go_sleep_mode(): | 26 def go_sleep_mode(): |
19 subprocess.run(['pmset', 'sleepnow']) | 27 subprocess.run(['pmset', 'sleepnow']) |
20 | 28 |
29 | |
21 is_screen_on() | 30 is_screen_on() |