bin env python coding utf-8 from re import search from commands import

 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
#!/bin/env python
# -*- coding: utf-8 -*-
from re import search
from commands import getoutput
import os
from time import sleep
_widgetName = 'volume'
_awesome_client_path = "%s/bin/awesome-client" % os.environ.get('HOME')
_spaces = ' ' * 4
if __name__ == "__main__":
while 1:
try:
g = search(r'.*Front Left:.*?\[(.*?)\].*?\[o(.*?)\].*', getoutput('amixer sget Master'))
vol = "[ %s%s]" % (
g.group(1),
((g.group(2) == 'n') and ' ') or ' (muted) '
)
pipe = os.popen(_awesome_client_path, 'w')
pipe.write("0 widget_tell %s %s%s\n" % (_widgetName, _spaces, vol))
pipe.close()
except:
pass
sleep(3)