From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: help-guix <help-guix@gnu.org>
Subject: A simple battery level alert mcron job for your Guix
Date: Mon, 22 Jul 2019 19:10:59 +0900 [thread overview]
Message-ID: <877e8axtu4.fsf@gmail.com> (raw)
If like me, you are using a minimalist WM, you might miss on basic
features such as a battery level gauge. Having a laptop silently die on
us due to forgetting to plug the AC charger can be frustrating...
So here's a small hack that should at least beep the PC speaker when the
battery goes below 20%. It relies on "acpi" to get the battery level
and "beep" to make use of the PC speaker.
--8<---------------cut here---------------start------------->8---
(use-service-module
...
base
mcron
...)
(use-package-modules
...
linux
terminals ; for "beep"
...)
;;; Allow the use of the PC speaker (beep) for any active user.
(define %pcspeaker-beep-rule
(udev-rule
"70-pcspkr-beep.rules"
(string-append "ACTION==\"add\", SUBSYSTEM==\"input\", "
"ATTRS{name}==\"PC Speaker\", ENV{DEVNAME}!=\"\", "
"TAG+=\"uaccess\"")))
(define %battery-alert-job
#~(job '(next-minute (range 0 60 1))
"(( $(acpi | cut -d',' -f2 | tr -d ' %') < 20 )) && beep -r5"))
(operating-system
...
(packages (cons* ...
acpi beep ;for the battery alert mcron job
%base-packages))
(services
(cons*
(service mcron-service-type
(mcron-configuration (jobs (list %battery-alert-job))))
...
(modify-services %desktop-services
(udev-service-type config =>
(udev-configuration
(inherit config)
(rules (cons* %pcspeaker-beep-rule
(udev-configuration-rules config)))))))))
--8<---------------cut here---------------end--------------->8---
One caveat: on my laptop at least, the mute button silences even the PC
speaker, leaving some room for more surprise shutdowns.
Have fun,
Maxim
next reply other threads:[~2019-07-22 1:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 10:10 Maxim Cournoyer [this message]
2019-08-01 0:07 ` A simple battery level alert mcron job for your Guix, v2 Maxim Cournoyer
2019-07-31 15:23 ` Ricardo Wurmus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877e8axtu4.fsf@gmail.com \
--to=maxim.cournoyer@gmail.com \
--cc=help-guix@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.