Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_volume.lua
blobfc028f398d4647c603552273b9c72d9ef3e12051
1 -- Authors: Benjamin Sigonneau
2 -- License: Public domain
3 -- Last Changed: Unknown
4 --
5 -- Public domain, written by Benjamin Sigonneau
6 -- Allows displaying volume information in the statusbar.
7 --
8 -- add some of the following fields into your template in cfg_statusbar.lua:
9 -- %volume_master
10 -- %volume_pcm
12 local unknown = "??", "??"
14 local function get_volume()
15 local f=io.popen('aumix -q','r')
16 local s=f:read('*all')
17 f:close()
18 local _, _, master, pcm =
19 string.find(s, "vol[0-9]? (%d*), .*\n"..
20 "pcm[0-9]? (%d*), .*\n"
23 if not master then
24 return unknow
25 elseif not pcm then
26 return unknow
27 end
29 return master.."%", pcm.."%"
30 end
33 local function inform(key, value)
34 statusd.inform("volume_"..key, value)
35 end
38 local volume_timer = statusd.create_timer()
40 local function update_volume()
41 local master, pcm = get_volume()
42 inform("master", master)
43 inform("pcm", pcm)
44 -- update every 10 seconds
45 volume_timer:set(10*1000, update_volume)
46 end
48 update_volume()