-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvol
More file actions
executable file
·76 lines (67 loc) · 2.12 KB
/
vol
File metadata and controls
executable file
·76 lines (67 loc) · 2.12 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 2018 Jared Daniel Carbonell Recomendable.
import sys
import subprocess
# Need to change these when porting this program for other sinks or computers.
sink = 0
# Default Commands and Error Messages
errormsg = '\nUnable to get volume.\nExiting...\n'
invalid_resp = '\nYou have entered an invalid response.\nExiting...\n'
com = 'pactl set-sink-mute {s} 0 && pactl set-sink-volume {s} {p}%'
comget = 'pactl list sinks | grep Volume'
def run(has_input, level=0):
"""Carry out the process of changing the volume of the system."""
if has_input == 1:
to_run = com.format(s=sink, p=level)
print(level)
subprocess.run(['bash', '-c', to_run])
elif has_input == 2:
volume = str(
subprocess.check_output(comget, shell=True)
).split('/ ')[1]
volume = volume.split('%')[0]
volume = volume.split(' ')[-1]
if volume.isnumeric():
volume = int(volume)
if level == 'u':
volume = min(100, volume + 1)
else:
volume = max(0, volume - 1)
run(1, volume)
else:
sys.exit(errormsg)
else:
temp_level = input('Volume [0-100, Default: 0]: ')
if temp_level == '':
run(1)
elif temp_level.isnumeric():
if 0 <= int(temp_level) < 101:
run(1, temp_level)
else:
sys.exit(invalid_resp)
else:
sys.exit(invalid_resp)
def show_help():
"""Show the help documentation for the program."""
help_doc = '''Usage: volume [percentage-level]
Level:
0 - lowest
100 - highest'''
print(help_doc)
if __name__ == '__main__':
if len(sys.argv) == 1:
run(False)
elif len(sys.argv) == 2:
if sys.argv[1].isnumeric():
vol = int(sys.argv[1])
if 0 <= vol < 101:
run(1, vol)
else:
show_help()
elif sys.argv[1] in ('d', 'u', 'down', 'up'):
run(2, sys.argv[1][0])
else:
show_help()
else:
show_help()