-
Notifications
You must be signed in to change notification settings - Fork 0
/
pa-vol.py
executable file
·52 lines (48 loc) · 1.67 KB
/
pa-vol.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# Maintained at: [email protected]:dareni/shellscripts.git
from sys import argv
import os
import logging
#logging.basicConfig(level=logging.DEBUG)
inc = 0x800
#sink = "alsa_output.pci-0000_00_1b.0.analog-stereo"
#sink = "alsa_output.pci-0000_00_1b.0"
#sink = os.popen('pacmd dump|grep set-default-sink').read().split(" ")[1]
pacmd = 'pactl'
def getSetting(sink, cmd):
command = pacmd + ' ' + cmd + ' ' + sink
logging.debug('command::::' + command)
resultList = os.popen(command).read()
logging.debug("result::::: " + resultList)
return resultList .rsplit(" ")
def setSetting(sink, cmd, value):
command = pacmd + ' ' + cmd + ' ' + sink + ' ' + str(value)
logging.debug('command::::' + command)
result = os.popen(command).read()
if len(argv) == 2:
sink = os.popen(pacmd + ' get-default-sink').read().strip()
option = argv[1]
if option == 'plus':
result = getSetting(sink, 'get-sink-volume')
volume = int(result[2], 10)
logging.debug("volume::::: " + str(volume))
volume += inc
if volume > 0x10000:
volume = 0x10000
setSetting(sink, 'set-sink-volume', volume)
elif option == 'minus':
result = getSetting(sink, 'get-sink-volume')
volume = int(result[2], 10)
volume -= inc
if volume < 0:
volume = 0x0
setSetting(sink, 'set-sink-volume', volume)
elif option == 'mute':
result = getSetting(sink, 'get-sink-mute')
if result[1].rstrip() == 'yes':
value = '0'
else:
value = '1'
setSetting(sink, 'set-sink-mute', value)
else:
print("usage pa-vol.py plus | minus | mute")