1 -- Authors: Randall Wald <randy@rwald.com>
2 -- License: GPL, version 2
3 -- Last Changed: Unknown
6 -- Volume level and state information script
7 -- Written by Randall Wald
8 -- email: randy@rwald.com
9 -- Released under the GPL
11 -- Based on a public domain script written by Benjamin Sigonneau
13 -- This script uses "amixer" to find volume information. If you don't have
14 -- "amixer," this script will fail. Sorry.
15 -- Though this is labeled "statusd_volume2.lua", rename it to
16 -- "statusd_volume.lua" to make it work.
18 -- Available monitors:
19 -- %volume_level Volume level, as a percentage from 0% to 100%
20 -- %volume_state The string "" if unmuted, "MUTE " if muted
23 -- template="[ %date || <other stuff> || vol: %volume_level %volume state]"
24 -- (note space between monitors but lack of space after %volume_state)
26 -- [ <Date> || <other stuff> || vol: 54% ]
28 -- [ <Date> || <other stuff> || vol: 54% MUTE ]
31 local function get_volume()
32 local f
=io
.popen('amixer','r')
33 local s
=f
:read('*all')
35 local _
, _
, master_level
, master_state
= string.find(s
, "%[(%d*%%)%] %[(%a*)%]")
36 local sound_state
= ""
37 if master_state
== "off" then
40 return master_level
.."", sound_state
..""
43 local function inform_volume(name
, value
)
44 if statusd
~= nil then
45 statusd
.inform(name
, value
)
47 io
.stdout
:write(name
..": "..value
.."\n")
50 local function inform_state(value
)
51 if statusd
~= nil then
52 statusd
.inform("volume_state", value
)
54 io
.stdout
:write("volume_state"..value
.."\n")
58 if statusd
~= nil then
59 volume_timer
= statusd
.create_timer()
62 local function update_volume()
63 local master_level
, sound_state
= get_volume()
64 inform_volume("volume_level", master_level
)
65 inform_volume("volume_state", sound_state
)
66 if statusd
~= nil then
67 volume_timer
:set(500, update_volume
)