help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Writing a Lisp to show the capacity of the battery of the laptop


From: Pascal J. Bourguignon
Subject: Re: Writing a Lisp to show the capacity of the battery of the laptop
Date: Tue, 22 Feb 2011 17:48:49 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Thomas Dean <tdean9db@gmail.com> writes:

> Hi,
>
> I'm using Archlinux. I want to write a lisp to show the remaining
> capacity of the battery of the laptop. It is expected to work like
> this:
>
> 1. Read from /proc/acpi/battery/BAT0/state and obtain the remaining
> capacity of the battery.
> 2. Read from /proc/acpi/battery/BAT0/info and obtain the full capacity
> of the battery.
> 3. By calculating remaining / full, get the percentage and print it.
>
> I writing the following lisp but it seems that it doesn't work.
>
> ;--------------------------------LISP---------------------------------
>
> ; get remaining capacity
> (shell-command
>  "cat /proc/acpi/battery/BAT0/state | grep \"remaining capacity\" | sed 
> \"s/^[a-z][a-z: ]*\([0-9][0-9]*\).*$/\1/g\""
>  "td-battery-temp-buffer")
> (set-buffer "td-battery-temp-buffer")
> (setq td-battery-full (string-to-number (buffer-string)))
> (erase-buffer)

(string-to-number (shell-command-to-string "..."))


> ; calculate percentage
> (message (concat "Remaining Capacity: " (number-to-string 
> td-battery-remaining)
>                "\nFull Capacity: " (number-to-string td-battery-full)))

(message "Remaining Capacity: %d\nFull Capacity: %d"
         td-battery-remaining td-battery-full)


But of course, as mentionned, M-x battery.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

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