2 -- Volume level and state information script
3 -- Written by Randall Wald
4 -- email: randy@rwald.com
5 -- Released under the GPL
7 -- Based on a public domain script written by Benjamin Sigonneau
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
19 -- template="[ %date || <other stuff> || vol: %volume_level %volume state]"
20 -- (note space between monitors but lack of space after %volume_state)
22 -- [ <Date> || <other stuff> || vol: 54% ]
24 -- [ <Date> || <other stuff> || vol: 54% MUTE ]
27 local function get_volume()
28 local f
=io
.popen('amixer -q','r')
29 local s
=f
:read('*all')
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
38 if master_level
== nil then
41 return master_level
.."", sound_state
..""
44 local function inform_volume(name
, value
)
45 if statusd
~= nil then
46 statusd
.inform(name
, value
)
48 io
.stdout
:write(name
..": "..value
.."\n")
51 local function inform_state(value
)
52 if statusd
~= nil then
53 statusd
.inform("volume_state", value
)
55 io
.stdout
:write("volume_state"..value
.."\n")
59 if statusd
~= nil then
60 volume_timer
= statusd
.create_timer()
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(10000, update_volume
)