From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Writing a Lisp to show the capacity of the battery of the laptop Date: Tue, 22 Feb 2011 17:48:49 +0100 Organization: Informatimago Message-ID: <87d3mkow0e.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1298396434 11946 80.91.229.12 (22 Feb 2011 17:40:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 22 Feb 2011 17:40:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 22 18:40:29 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PrwDt-0004AE-LT for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Feb 2011 18:40:29 +0100 Original-Received: from localhost ([127.0.0.1]:38965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrwDt-0005bm-8n for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Feb 2011 12:40:29 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 42 Original-X-Trace: individual.net gsWAYFkI/Amf0YNPyxonXQ7YlmzWbA+PK/KD1PgGg46NY0xHxP Cancel-Lock: sha1:ODdjNGM2YzZmYzkyMWQ0Y2ZmZTdjMGQwYTgyMjQyZmI0ODJlOTFmZQ== sha1:x0hzjM7NpPkpfhon8P+yRb61LRg= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:185174 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:79342 Archived-At: Thomas Dean 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 {}.