Monday, January 18, 2010

Geektool Setup

Geektool is a system preference pane that allows you to display different information on your desktop.

Here's my setup:




Disk Information
Type: Shell
Command: df -h
Output:

Filesystem      Size   Used  Avail Capacity  Mounted on
/dev/disk0s2   186Gi  182Gi  4.1Gi    98%    /
devfs          113Ki  113Ki    0Bi   100%    /dev
map -hosts       0Bi    0Bi    0Bi   100%    /net
map auto_home    0Bi    0Bi    0Bi   100%    /home
Notes:
I normally use this to see how much space I'm using on my drives.

System Log
Type: File
File: system.log
Output: Too long to list
Notes:
A running system.log is pretty useful. If anything seems to be misbehaving, I can check the log and see if there's any crazy going on. I usually only show about 5 or 6 lines of the log.

Swapfiles
Type: Shell
Command: ls -alh /var/vm
Output:
total 16777216
drwxr-xr-x  16 root  wheel   544B Jan 18 12:10 .
drwxr-xr-x  26 root  wheel   884B Aug 30 15:45 ..
-rw------T   1 root  wheel   3.0G Jan 18 09:01 sleepimage
-rw-------   1 root  wheel    64M Jan  5 17:53 swapfile0
-rw-------   1 root  wheel    64M Jan 18 14:05 swapfile1
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile10
-rw-------   1 root  wheel   512M Jan 18 13:23 swapfile11
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile12
-rw-------   1 root  wheel   128M Jan 18 14:05 swapfile2
-rw-------   1 root  wheel   256M Jan 18 14:05 swapfile3
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile4
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile5
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile6
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile7
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile8
-rw-------   1 root  wheel   512M Jan 18 14:05 swapfile9
Notes:
As you can see, I'm using quite a bit of disk space on the swapfiles. Right now, most of these are the result of having Safari open with a ton of windows. Mostly, this helps me figure out why I suddenly lost 6GB of space.

Uptime and System Load
Type: Shell
Command: /usr/bin/uptime
Output:
14:08  up 12 days, 20:16, 3 users, load averages: 1.19 1.28 1.16
Notes:
Self-explanatory for the most part.


Battery Info
Type: Shell
Command: perl /path/to/perlscript.pl
The perlscript.pl contains the following code:


#!/usr/bin/perl


my $charge = 0;
my $full = 0;
my $amperage = 0;
my $voltage = 0;
my $cycles = 0;


@powerinfo = `system_profiler SPPowerDataType`;


foreach $item (@powerinfo)
{
if ($item =~ /apacity/)
{
@temp = split(/:/, $item);
$temp[1] =~ s/\n//g;
$temp[1] =~ s/\r//;
$temp[1] =~ s/ //gi;
$full = $temp[1];
}


if ($item =~ /remaining/)
{
@temp = split(/:/, $item);
$temp[1] =~ s/\n//g;
$temp[1] =~ s/\r//;
$temp[1] =~ s/ //gi;
$charge = $temp[1];
}


if ($item =~ /Amperage/)
{
@temp = split(/:/, $item);
$temp[1] =~ s/\n//g;
$temp[1] =~ s/\r//;
$temp[1] =~ s/ //gi;
$amperage = $temp[1];
}


if ($item =~ /Voltage/)
{
@temp = split(/:/, $item);
$temp[1] =~ s/\n//g;
$temp[1] =~ s/\r//;
$temp[1] =~ s/ //gi;
$voltage = $temp[1];
}


if ($item =~ /Cycle/)
{
@temp = split(/:/, $item);
$temp[1] =~ s/\n//g;
$temp[1] =~ s/\r//;
$temp[1] =~ s/ //gi;
$cycles = $temp[1];
}
}




print "$charge/$full mAh | $amperage mA | $voltage mV | $cycles cy | ";


if ($amperage < 0)
{
$chargetime = $charge / $amperage * -1 * 60;
}
else
{
$chargetime = ($full - $charge) / $amperage * 60;
}


print int(($charge/$full)*100) . "%" . 
" | " . int($chargetime) . " min".
"\n\n";
Output:
4207/4831 mAh | 888 mA | 12456 mV | 162 cy | 87% | 42 min
Notes:
This one took a bit of figuring out. The command system_profiler SPPowerDataType provides all the necessary info, and the Perl script parses that and formats it properly.
Some notable formulas:
% Charge: current charge / capacity (in mAh)
Charge Time:
When on battery, amperage is listed as a negative number since power is being drawn from the battery so we need to multiply by -1 to get a positive value. In that case, the formula is - current charge / amperage * -1 * 60 (in minutes)
When the charger is plugged in, amperage is listed as a positive number representing how much power is being sent to the battery. You also have to calculate how many mAh are left to go for a full charge. In that case, the formula is - (capacity - current charge) / amperage * 60 (in minutes)


Charging Indicator, Battery Health Indicator, and SMART status
Type: Shell (check Display status feedback image)
Command:
system_profiler SPPowerDataType | grep Charging | grep Yes > /dev/null
system_profiler SPPowerDataType | grep Condition | grep Normal > /dev/null
diskutil info disk0s2 | grep Verified > /dev/null
Output:
Charging Indicator: Green if charging; Red if on battery
Battery Health Indicator: Green if normal; Red if replace soon or other abnormal status
SMART Status: Green if ok; Red if otherwise