v0.2 of my new desktop design made with GeekTool
During the rainy weekend i spent some time to fiddle around a bit with the
“geektool”.
After researching a bit about shell programming and
reviewing a lot of scripts and examples i wrote some for myself.
With a good looking wallpaper and the script collection in place this is the result (for now).
Note: credits for the wallpaper found on deviantart.com
Weather, CPU, Network I/O, RAM Usage, HDD Usage, Processes, Memory Hogs, Calendar, Google Mail (unread)
Weather
displays the current wheather, the forecast for tomorrow and the day after and an image of the current condition.
#!/bin/sh
# displays the current wheather condition and saves an appropriate image
# as well as the forecast for tomorrow and the day after
TMP_DIR=/tmp/; # the tmp working-directory
TMP_FILE=weather.xml; # the name of the .tmp file
file=$TMP_DIR/$TMP_FILE; # the tmp file
REGION_URI=germany/berlin/berlin-20065565/; # the url for berlin, germany
CITY_CODE=GMXX0007; # the region code for berlin, germany
#
# get the image for the current conditions
#
curl -s -o $TMP_DIR/weather.html 'http://weather.yahoo.com/'$REGION_URI;
curl -s -o $TMP_DIR/weather.png |
`grep "div class="forecast-icon" style="background:url" |
$TMP_DIR/weather.html |
awk -F"'" '{ printf $2 }'`
#
# get the forecast
#
curl -s -o $file 'http://xml.weather.yahoo.com/forecastrss?p='$CITY_CODE'&u;=c'
#
# tomorrow
#
more $file | grep -E -m 1 '(High:)'|
sed -e 's/<br></br>//'
-e 's/<b>//' -e 's/< /b>//'
-e 's/<br></br>//' -e 's/<br></br>//'
-e 's/High://g' -e 's/Low:/-/g'
#
# the day after tomorrow
#
more $file | grep -E -m 2 '(High:)' |
sed -e 's/<br></br>//'
-e 's/</b><b>//' -e 's/< /b>//'
-e 's/<br></br>//'
-e 's/High://g' -e 's/Low:/-/g' |
tail -r -n 1
CPU Usage
# displays the cpu usage for user/system/idle
#!/bin/sh
# displays the cpu usage for user/system/idle
TMP_DIR=/tmp
ps -arcwwxo "command %cpu ruser" |
head -11 |
sed '/top/d' > $TMP_DIR/cpu.temp
cat $TMP_DIR/cpu.temp |
head -11 |
sed -e "s/COMMAND/Processes/g" -e 's/ %CPU RUSER//'
Network I/O
# displays the current I/O of a network adapter
#!/bin/sh
# displays the current I/O of a specified network adapter
# created by chris helming.
# chris dot helming at gmail
# get the current number of bytes in and bytes out
myvar1=`netstat -ib | grep -e "en0" -m 1 | awk '{print $7}'` # bytes in
myvar3=`netstat -ib | grep -e "en0" -m 1 | awk '{print $10}'` # bytes out
# wait one second
sleep 1
# get the number of bytes in and out one second later
myvar2=`netstat -ib | grep -e "en0" -m 1 | awk '{print $7}'` # bytes in again
myvar4=`netstat -ib | grep -e "en0" -m 1 | awk '{print $10}'` # bytes out again
# find the difference between bytes in and out during that one second
subin=$(($myvar2 - $myvar1))
subout=$(($myvar4 - $myvar3))
# convert bytes to kilobytes
kbin=`echo "scale=2; $subin/1024;" | bc`
kbout=`echo "scale=2; $subout/1024;" | bc`
# print the results
echo "Network I/O"
echo "D: $kbin Kb/sec"
echo "U: $kbout Kb/sec"
RAM Usage
# displays the current RAM usage
#!/bin/sh
# displays the current RAM usage
top -FR -l 1 | awk '/PhysMem/ {print "Used: " $8 " Free: " $10}'
HDD Usage
# displays the space of specified hdd’s
#!/bin/sh
# displays the space of specified hdd's (internal, external Time-Machine Backup)
df -h | grep disk0s2 | awk '{print "HDD #1: " $4 " (" $5 " used)"}' # internal
df -h | grep "Time" | awk '{print "HDD #2: " $4 " (" $5 " used)"}' # external
Processes
# displays the 10 most cpu greedy processes
#!/bin/sh
# displays the 10 most cpu greedy processes
TMP_DIR=/tmp
ps -arcwwxo "command %cpu ruser" | head -11 | sed '/top/d' > $TMP_DIR/cpu.temp
more $GT_DIR/cpu.temp |
head -11 | \
sed -e "s/COMMAND/Processes/g" \
-e 's/ %CPU RUSER//'
Memory Hogs
# displays the 10 most memory greedy processes
#!/bin/sh
# displays the 10 most memory greedy processes
top -orsize -FR -l1 | \
grep % | \
grep -v \Load | \
grep -v \COMMAND | \
cut -c 7-19,64-69 | \
head -10
Calendar
# displays the calendar of the current month
#!/bin/sh
# displays the calendar of the current month
cal
Google Mail (unread messages)
# displays the unread emails from #inbox
#!/bin/sh
# Thanks to Dave Taylor at www.askdavetaylor.com for
# the great tutorial on accessing and parsing RSS feeds with a shell script
# displays the unread emails from #inbox
username='' # username is your email address with @ replaced by %40.
password='' # your password
url="https://$username:$password@mail.google.com/mail/feed/atom/inbox"
if [ $# -eq 1 ] ; then
headarg=$(( $1 * 2 ))
else
headarg="-8" # default is four email messages
fi
curl -s $url | grep -E '(title>|summary>)' | \
sed -n '2,$p' | \
sed -e 's/<title>//' -e 's/< /title>//' \
-e 's/<summary>/ /' -e 's/< /summary>//' | \
head $headarg | \
fmt -w $width
this is it for now.. #ilovemygeektoolstyleddesktop ;)
~david