From owner-freebsd-mobile Sun Nov 9 19:24:59 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id TAA28032 for mobile-outgoing; Sun, 9 Nov 1997 19:24:59 -0800 (PST) (envelope-from owner-freebsd-mobile) Received: from word.smith.net.au (vh1.gsoft.com.au [203.38.152.122]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id TAA28024 for ; Sun, 9 Nov 1997 19:24:50 -0800 (PST) (envelope-from mike@word.smith.net.au) Received: from word.smith.net.au (localhost.gsoft.com.au [127.0.0.1]) by word.smith.net.au (8.8.7/8.8.5) with ESMTP id NAA00665; Mon, 10 Nov 1997 13:50:01 +1030 (CST) Message-Id: <199711100320.NAA00665@word.smith.net.au> X-Mailer: exmh version 2.0zeta 7/24/97 To: Warner Losh cc: mobile@freebsd.org Subject: Re: A little tk program In-reply-to: Your message of "Sun, 09 Nov 1997 19:27:46 PDT." <199711100227.TAA20649@harmony.village.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 10 Nov 1997 13:50:00 +1030 From: Mike Smith Sender: owner-freebsd-mobile@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > ok. I have a small tcl/tk prorgam that works under tk 4.2 (since I > have ical installed). It displays the current battary level. It > should work with 8.0 as well. Enjoy. Comments welcome. Only about > 1M of memory is needed :-(. ... but if ical is running that's shared. 8) If you were feeling enthusiastic, you could have it change its icon title while minimised, eg. from [##########] 100 to [ ] 0... > Warner > > P.S. You need to run this as root, or have apm be setuid root. Er, I don't think so. Certainly, apm will give me power status as non-root. > P.P.S. Mike Smith: now I understand why you like tk so much.... *grin* > scale .scale -from 0 -to 100 \ > -length 100 \ > -variable batteryLevel \ > -orient horizontal \ > -showvalue true Wow, now I can set the battery level too! 8) Here's a slightly modified version that implements a bargraph in the icon title, adds some colour and shrinks it a little to make the most of precious laptop real estate. You might also want to configure your window manager to hide the decorations on the window to make it smaller again. mike #!/bin/sh # tcl magic \ exec wish8.0 -f $0 $* proc updateBattery {} { global batteryLevel; set batteryLevel [exec apm -l]; set hashes [string range "##########" 0 [expr $batteryLevel / 10]]; wm iconname . [format "\[%-10s\] %d%%" $hashes $batteryLevel]; if {$batteryLevel < 20} { .scale configure -troughcolor red; } else { if {$batteryLevel < 40} { .scale configure -troughcolor yellow; } else { .scale configure -troughcolor green; } } after 30000 updateBattery; } label .label -text "Battery Level" -font 6x10; pack .label -side left; scale .scale -from 0 -to 100 \ -length 100 \ -variable batteryLevel \ -orient horizontal \ -showvalue true \ -font 5x8 \ -width 5 \ -sliderlength 4 \ -state disabled; pack .scale -side right; wm title . "batterylevel"; update idletasks; wm resizable . 0 0; updateBattery;