2
|
1 import subprocess
|
3
|
2 import ast
|
|
3
|
2
|
4
|
|
5 def is_screen_on():
|
3
|
6 screen_is_locked = ast.literal_eval(
|
|
7 subprocess.check_output(
|
|
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
|
2
|
16
|
|
17
|
|
18 def go_lock_screen():
|
|
19 pass
|
|
20
|
|
21
|
|
22 def go_wake_screen():
|
|
23 pass
|
|
24
|
|
25
|
|
26 def go_sleep_mode():
|
|
27 subprocess.run(['pmset', 'sleepnow'])
|
|
28
|
3
|
29
|
2
|
30 is_screen_on() |