help-guix
[Top][All Lists]
Advanced

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

Re: A simple battery level alert mcron job for your Guix, v2


From: Ricardo Wurmus
Subject: Re: A simple battery level alert mcron job for your Guix, v2
Date: Wed, 31 Jul 2019 17:23:16 +0200
User-agent: mu4e 1.2.0; emacs 26.2

Maxim Cournoyer <address@hidden> writes:

> The following mcron job accomplish this.  I've implemented it in Guile
> Scheme this time around and was puzzled that I had to use program-file
> to make it work, otherwise srfi-26's cut would error on undefined symbol
> '<>'.
>
> The problem was that passing the code as a lambda would have the syntax
> imported not a the top level, which is the only valid place to
> define/import syntax definitions, per the Guile manual.  Using
> `program-file' works around that, by placing the logic at the top level
> of a standalone script, while allowing you to define everything at the
> level of your Guix config file.

Ah, thanks for investigating this.  When you first asked about this I
was really quite puzzled.

>        (let* ((input-pipe (open-pipe* OPEN_READ
>                                       #$(file-append acpi "/bin/acpi")))
>               (output (get-string-all input-pipe))
>               (m (string-match "Discharging, ([0-9]+)%" output))
>               (level (and=> m (compose string->number
>                                        (cut match:substring <> 1)))))
>          (when (and=> level (cut <= <> %min-level))
>            (format #t "warning: Battery level is low (~a%)~%" level)
>            (invoke #$(file-append beep "/bin/beep") "-r5")))))))

Perhaps and-let* (SRFI 2) would be of interest here.

-- 
Ricardo




reply via email to

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