-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolume
More file actions
executable file
·41 lines (28 loc) · 958 Bytes
/
Copy pathvolume
File metadata and controls
executable file
·41 lines (28 loc) · 958 Bytes
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
#!/usr/bin/env python3
import subprocess
import colors
import re
fontawesome = {
'volume-high': '\uf028', #
'volume-low': '\uf027', #
'volume-off': '\uf026', #
'volume-xmark': '\uf6a9', #
}
amixer_get_master = subprocess.run(['amixer', 'get', 'Master'], universal_newlines=True, check=False, capture_output=True)
if amixer_get_master.returncode != 0:
print(colors.error(fontawesome['volume-xmark'] + ' UNKNOWN'))
exit(0)
output = amixer_get_master.stdout
if '[off]' in output:
print(colors.warning(fontawesome['volume-off'] + ' MUTED'))
exit(0)
percentages = re.findall(r'\[(\d+)%\]', output)
percentages = list(map(int, percentages))
average_percentage = sum(percentages) // len(percentages)
if average_percentage == 0:
icon = 'volume-off'
elif average_percentage < 50:
icon = 'volume-low'
else:
icon = 'volume-high'
print('{} {}%'.format(fontawesome[icon], average_percentage))