Geektool Scripts
System Statistics:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Weather | |
lynx -dump http://printer.wunderground.com/cgi-bin/findweather/getForecast?query=ZIPCODE|awk '/Temp/{printf $2, ": "; for (i=3; i<=3; i++) printf $i " " }' | |
#Conditions | |
lynx -dump http://printer.wunderground.com/cgi-bin/findweather/getForecast?query=ZIPCODE|awk '/Cond/ && !/Fore/ {for (i=2; i<=10; i++) printf $i " " }' | |
#uptime | |
uptime | awk '{print "UPTIME : " $3 " " $4 " " $5 " " }'; | |
#RAM usage | |
top -l 1 | awk '/PhysMem/ {print "RAM : " $8 " "}' ; |
Display IP Address bash Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
myen0=`ifconfig en0 | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'` | |
if [ "$myen0" != "" ] | |
then | |
echo "Ethernet : $myen0" | |
else | |
echo "Ethernet : Not Found" | |
fi | |
myen1=`ifconfig en1 | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'` | |
if [ "myen1" != "" ] | |
then | |
echo "AirPort : $myen1" | |
else | |
echo "Airport : Not Found" | |
fi |
Battery Status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# OSX Battery Status | |
# battery.pl | |
# | |
# Perl script that displays to the terminal the charge on your Mac Intel battery (and takes | |
# a guess as to how much time is left on the charge). | |
use strict; | |
use Data::Dumper; | |
my $IOREG = "/usr/sbin/ioreg"; | |
my $output = `$IOREG -nAppleSmartBattery`; | |
my @output = split("\n", $output); | |
my $batteryHash; | |
foreach (@output) { | |
if (/\"(MaxCapacity)\"\s+=\s+(\d+)/) { | |
$batteryHash->{$1} = $2; | |
} elsif (/\"(DesignCapacity)\"\s+=\s+(\d+)/) { | |
$batteryHash->{$1} = $2; | |
} elsif (/\"(CurrentCapacity)\"\s+=\s+(\d+)/) { | |
$batteryHash->{$1} = $2; | |
} elsif (/\"(AvgTimeToEmpty)\"\s+=\s+(\d+)/) { | |
$batteryHash->{$1} = $2; | |
} elsif (/\"(AvgTimeToFill)\"\s+=\s+(\d+)/) { | |
$batteryHash->{$1} = $2; | |
} elsif (/\"(TimeRemaining)\"\s+=\s+(\d+)/) { | |
$batteryHash->{$1} = $2; | |
} elsif (/\"(IsCharging)\"\s+=\s+(\w+)/) { | |
$batteryHash->{$1} = $2; | |
} elsif (/\"(FullyCharged)\"\s+=\s+(\w+)/) { | |
$batteryHash->{$1} = $2; | |
} | |
} | |
my $DEBUG = 0; | |
print Dumper $batteryHash if $DEBUG; | |
my $percentCapacity = ( $batteryHash->{"CurrentCapacity"} / $batteryHash->{"MaxCapacity"} ) * 100; | |
$percentCapacity = int($percentCapacity + .5 * ($percentCapacity <=> 0)); | |
my $timeLeft; | |
if ($batteryHash->{"IsCharging"} eq "Yes" && $batteryHash->{"FullyCharged"} eq "No") { | |
# battery is charging so can't calculate time left (yet) | |
$timeLeft = "( + )"; | |
# $timeLeft = "(~/~)"; | |
} elsif ($batteryHash->{"FullyCharged"} eq "Yes") { | |
$timeLeft = "( f )"; | |
} elsif ($percentCapacity != 100) { | |
# OK, calculate time left | |
$timeLeft = $batteryHash->{"TimeRemaining"} / 60; | |
my ($hours, $minutes) = split(/\./, $timeLeft); | |
$minutes = 60 * ( "." . $minutes ); | |
$minutes = int($minutes + .005 * ($minutes <=> 0)); | |
$minutes = sprintf ("%02d", $minutes); | |
$timeLeft = "($hours:$minutes)"; | |
} else { | |
# not charging and 100% capacity | |
# $timeLeft = "( - )"; | |
$timeLeft = "( f )"; | |
} | |
print "Battery: $percentCapacity%\nTime Left : $timeLeft\n"; | |
exit; |
Scrubbing two lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
# Remove one list from another bigger list | |
# Usage : perl filter.pl file1 file2 > output | |
# This will remove file2 elements from file1 and store it to output | |
$source=shift; | |
printhelp() if (! $source); | |
$remove=shift; | |
open(FILTER, "<$remove") || die "Can't open $remove\n"; | |
open(SOURCE, "<$source") || die "Can't open $source\n"; | |
$filter=""; | |
while (<FILTER>) | |
{ | |
$data=$_; | |
chomp($data); | |
$filter.=" $data "; | |
} | |
$notfilter=0; | |
$filtered=0; | |
while (<SOURCE>) | |
{ | |
$data=$_; | |
chomp($data); | |
if ($filter=~/ $data /) | |
{ | |
$filtered++; | |
} | |
else | |
{ | |
$notfilter++; | |
print $data . "\n"; | |
} | |
} | |
print "Removed: " . $filtered . "\n"; | |
print "Left: " . $notfilter . "\n"; | |
sub printhelp() | |
{ | |
print <<END; | |
Usage: | |
perl filter.pl $list $removelist | |
END | |
} |