-
Notifications
You must be signed in to change notification settings - Fork 0
/
closelid.py
executable file
·36 lines (29 loc) · 1.06 KB
/
closelid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys, subprocess
def main():
guid = subprocess.check_output(['powercfg', '-getactivescheme'],
universal_newlines=True).split()[3]
args = sys.argv[1:]
if '-h' in args or '--help' in args or len(args) not in (1, 2):
print('''\
useage: closelid.py BATTERY CHARGING
values:
Do nothing: 0
Sleep: 1
Hibernate: 2
Shut down: 3
''')
lines = subprocess.check_output(
['powercfg', '-query', guid, 'sub_buttons', 'lidaction'],
universal_newlines=True).splitlines()
oldac, olddc = [int(lines[n].split()[-1], 16) for n in (14, 15)]
print('current settings:', olddc, oldac)
return
dcval = args[0]
acval = args[1] if len(args) == 2 else dcval
subprocess.call(['powercfg', '-setdcvalueindex', guid, 'sub_buttons',
'lidaction', dcval])
subprocess.call(['powercfg', '-setacvalueindex', guid, 'sub_buttons',
'lidaction', acval])
subprocess.call(['powercfg', '-setactive', guid])
if __name__ == '__main__':
main()