[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A simple battery level alert mcron job for your Guix

From: Maxim Cournoyer
Subject: A simple battery level alert mcron job for your Guix
Date: Mon, 22 Jul 2019 19:10:59 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

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---

 terminals                      ; for "beep"

;;; Allow the use of the PC speaker (beep) for any active user.
(define %pcspeaker-beep-rule
   (string-append "ACTION==\"add\", SUBSYSTEM==\"input\", "
                  "ATTRS{name}==\"PC Speaker\", ENV{DEVNAME}!=\"\", "

(define %battery-alert-job
  #~(job '(next-minute (range 0 60 1))
         "(( $(acpi | cut -d',' -f2 | tr -d ' %') < 20 )) && beep -r5"))

 (packages (cons* ...
                  acpi beep             ;for the battery alert mcron job

   (service mcron-service-type
            (mcron-configuration (jobs (list %battery-alert-job))))
   (modify-services %desktop-services
    (udev-service-type config =>
                        (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,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]