#!/bin/csh #\ exec wish $0 $* # A simple script to draw the battery power. The script repeatedly # calls apm (once a minute) to determine the battery power. It # draws the power as a colored verticle bar in one of four colors: # green: high power # yellow: low power # red: critical power # cyan: charging # Further, if the power is critical, the script beeps and raises its # window. The percent power remaining is displayed at the bottom # Lots could be added. Here's a short wish list: # Display of battery time remaining # Indication if plugged in or not # Settable polling time (ie, rather than 1 minute, let the user choose) # No title bar set title $argv0 set description "Graphical APM" wm title . "Graphical APM" wm minsize . 10 100 wm maxsize . 30 100 # stores the current draw type set drawtype line #..............................................................................# Create the canvas to draw in. # The frame is used to put a nice border around the canvas #..............................................................................frame .f -bd 2 -relief raised canvas .f.c -width 30 -height 100 bind all {destroy %W} bind all {destroy %W} pack .f -side top pack .f.c # Callback, gets called when the left mouse button is pressed bind .f.c { apm raise . } proc apm {} { set p [exec apm] set pl [split $p] set bstat [string trim [lindex $pl [expr {[llength $pl] - 3}]] :] set per [string trim [lindex $pl [expr {[llength $pl] - 2}]] %] set time [lindex $pl end] .f.c delete all switch $bstat { high {set c green} low {set c yellow} critical {set c red; bell; raise .f} charging {set c cyan} } .f.c create rectangle 0 100 30 [expr 100 - $per] -fill $c set t [.f.c create text 15 90 -text $per] } proc sleep {} { after [expr 60*1000] {apm; sleep} } apm sleep