[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
darwin-battery.el
From: |
Joe Corneli |
Subject: |
darwin-battery.el |
Date: |
Tue, 23 Aug 2005 01:26:57 -0500 |
;;; darwin-battery.el --- echo battery percent remaining under darwin
;; Copyright (C) 2005 Joe Corneli <address@hidden>
;; Time-stamp: <jac -- Tue Aug 23 01:30:57 CDT 2005>
;; This file is not part of GNU Emacs, but it is distributed under
;; the same terms as GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 2, or (at your
;; option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; `battery' from battery.el seems to be broken for Darwin users.
;; This displays the basic data (percent of battery life remaining).
;;; Code:
(defun darwin-battery ()
(interactive)
(let* ((batdat (shell-command-to-string
"/usr/sbin/ioreg -p IODeviceTree -n \"battery\" -w 0 | grep
IOBatteryInfo"))
(current (with-temp-buffer (insert batdat)
(goto-char (point-min))
(search-forward-regexp
"\"Current\"=\\([0-9]*\\)")
(string-to-int (match-string 1))))
(capacity (with-temp-buffer (insert batdat)
(goto-char (point-min))
(search-forward-regexp
"\"Capacity\"=\\([0-9]*\\)")
(string-to-int (match-string 1)))))
(message "%d%%" (* (/ (float current) capacity) 100))))
(defalias 'battery 'darwin-battery)
;;; darwin-battery.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- darwin-battery.el,
Joe Corneli <=