From mboxrd@z Thu Jan 1 00:00:00 1970 From: Maxim Cournoyer Subject: A simple battery level alert mcron job for your Guix Date: Mon, 22 Jul 2019 19:10:59 +0900 Message-ID: <877e8axtu4.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:32780) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpMrM-00013g-OB for help-guix@gnu.org; Sun, 21 Jul 2019 21:11:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpMrL-0006qX-Pf for help-guix@gnu.org; Sun, 21 Jul 2019 21:11:24 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:33774) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hpMrL-0006pg-I8 for help-guix@gnu.org; Sun, 21 Jul 2019 21:11:23 -0400 Received: by mail-pf1-x435.google.com with SMTP id g2so16550190pfq.0 for ; Sun, 21 Jul 2019 18:11:22 -0700 (PDT) Received: from x200 ([240f:c7:38e9:1:314b:485c:9ba4:72c6]) by smtp.gmail.com with ESMTPSA id z13sm32125594pjn.32.2019.07.21.18.11.19 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 21 Jul 2019 18:11:20 -0700 (PDT) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+gcggh-help-guix=m.gmane.org@gnu.org Sender: "Help-Guix" To: help-guix 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