1 -- Authors: Greg Steuck, Gerald Young <ion3script@gwy.org>
2 -- License: Public domain
3 -- Last Changed: Unknown
5 -- Public domain, written by Greg Steuck
6 -- Edited and updated by Gerald Young -- ion3script@gwy.org
7 -- This works on FreeBSD's apm (5.x) program added some color to indicate
8 -- AC connection and status (Charging, low, critical)
9 -- Allows displaying apm information in the statusbar.
11 -- save this file into ~/.ion3/statusd_apm.lua,
12 -- copy the default cfg_statusbar.lua to ~/.ion3, edit it to include (~line 81):
17 -- add some of the following fields into your template in cfg_statusbar.lua:
18 -- %apm_ac: A/C cable on-line (connected) off-line (disconnected)
19 -- %apm_pct: percent of remaining battery
20 -- %apm_estimate: time remaining based upon usage ... or whatever apm thinks.
21 -- %apm_state: Status: charging/high/low/critical
22 -- in cfg_statusbar.lua, about line 28, add the next line without the leading "--"
23 -- template="[ %date || load:% %>load_1min || battery: %apm_pct AC: %apm_ac Status: %apm_state ]",
24 -- If you've already customized your template= line, then simply add the field(s) where you want.
26 local unknown
= "?", "?", "?", "?"
28 -- Runs apm utility and grabs relevant pieces from its output.
29 -- Most likely will only work on OpenBSD due to reliance on its output pattern.
31 local f
=io
.popen('/usr/sbin/apm', 'r')
35 local s
=f
:read('*all')
37 local _
, _
, ac
, state
, pct
, estimate
=
39 "AC Line status: (.*)\n"..
40 "Battery Status: (.*)\n"..
41 "Remaining battery life: (.*)\n"..
42 "Remaining battery time: (.*)\n"
47 return state
, pct
, estimate
, ac
50 local function inform(key
, value
)
51 statusd
.inform("apm_"..key
, value
)
54 local apm_timer
= statusd
.create_timer()
56 local function update_apm()
57 local state
, pct
, estimate
, ac
= get_apm()
60 stateinf
= "important"
62 if state
== "critical" then
65 if state
== "charging" then
66 stateinf
= "important"
68 inform("state", state
)
69 inform("state_hint", stateinf
)
71 inform("estimate", estimate
)
72 if ac
== "off-line" then
75 if ac
== "on-line" then
79 inform("ac_hint", stateinf
)
80 apm_timer
:set(60*1000, update_apm
)