[UP] use ion3-plus haha.
[arrow.git] / archlinux_conf / etc / ion3 / old / statusd_volume.lua
blobc2fc96d241b66ef441e33603e6e947cc9739316d
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 if f == nil then
30 return "NIL", ""
31 end
32 local s=f:read('*all')
33 f:close()
34 --local _, _, master_level, master_state = string.find(s, "%[(%d*%%)%] %[(%a*)%]")
35 local _, _, master_level, master_state = string.find(s, "%[(%d*%%)%].*%[(%a*)%]")
37 local sound_state = ""
38 if master_state == "off" then
39 sound_state = "MUTE"
40 end
41 if master_level == nil then
42 master_level = "FAIL"
43 end
44 return master_level.."", sound_state..""
45 end
47 local function inform_volume(name, value)
48 if statusd ~= nil then
49 statusd.inform(name, value)
50 else
51 io.stdout:write(name..": "..value.."\n")
52 end
53 end
54 local function inform_state(value)
55 if statusd ~= nil then
56 statusd.inform("volume_state", value)
57 else
58 io.stdout:write("volume_state"..value.."\n")
59 end
60 end
62 if statusd ~= nil then
63 volume_timer = statusd.create_timer()
64 end
66 local function update_volume()
67 local master_level, sound_state = get_volume()
68 inform_volume("volume_level", master_level)
69 inform_volume("volume_state", sound_state)
70 if statusd ~= nil then
71 volume_timer:set(7000, update_volume)
72 else
73 volume_timer:set(9000, update_volume)
74 end
75 end
77 update_volume()