[UP] change update interval.
[arrow.git] / archlinux_conf / etc / ion3 / statusd_volume.lua
blob8d9745c6dd97b21f66a307891b60f53f663a086e
1 -- statusd_volume2.lua
2 -- Volume level and state information script
3 -- Written by Randall Wald
4 -- email: randy@rwald.com
5 -- Released under the GPL
6 --
7 -- Based on a public domain script written by Benjamin Sigonneau
8 --
9 -- This script uses "amixer" to find volume information. If you don't have
10 -- "amixer," this script will fail. Sorry.
11 -- Though this is labeled "statusd_volume2.lua", rename it to
12 -- "statusd_volume.lua" to make it work.
14 -- Available monitors:
15 -- %volume_level Volume level, as a percentage from 0% to 100%
16 -- %volume_state The string "" if unmuted, "MUTE " if muted
18 -- Example use:
19 -- template="[ %date || <other stuff> || vol: %volume_level %volume state]"
20 -- (note space between monitors but lack of space after %volume_state)
21 -- This will print
22 -- [ <Date> || <other stuff> || vol: 54% ]
23 -- when unmuted but
24 -- [ <Date> || <other stuff> || vol: 54% MUTE ]
25 -- when muted.
27 local function get_volume()
28 local f=io.popen('amixer -q','r')
29 local s=f:read('*all')
30 f:close()
31 --local _, _, master_level, master_state = string.find(s, "%[(%d*%%)%] %[(%a*)%]")
32 local _, _, master_level, master_state = string.find(s, "%[(%d*%%)%].*%[(%a*)%]")
34 local sound_state = ""
35 if master_state == "off" then
36 sound_state = "MUTE"
37 end
38 if master_level == nil then
39 master_level = "FAIL"
40 end
41 return master_level.."", sound_state..""
42 end
44 local function inform_volume(name, value)
45 if statusd ~= nil then
46 statusd.inform(name, value)
47 else
48 io.stdout:write(name..": "..value.."\n")
49 end
50 end
51 local function inform_state(value)
52 if statusd ~= nil then
53 statusd.inform("volume_state", value)
54 else
55 io.stdout:write("volume_state"..value.."\n")
56 end
57 end
59 if statusd ~= nil then
60 volume_timer = statusd.create_timer()
61 end
63 local function update_volume()
64 local master_level, sound_state = get_volume()
65 inform_volume("volume_level", master_level)
66 inform_volume("volume_state", sound_state)
67 if statusd ~= nil then
68 volume_timer:set(7000, update_volume)
69 else
70 volume_timer:set(9000, update_volume)
71 end
72 end
74 update_volume()