<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I Am Awesome &#187; bash</title>
	<atom:link href="http://iamawesome.net/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://iamawesome.net</link>
	<description>Pretending the Internet cares about me since 2009.</description>
	<lastBuildDate>Wed, 07 Jul 2010 17:08:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>My GeekTool Setup</title>
		<link>http://iamawesome.net/2009/04/my-geektool-setup/</link>
		<comments>http://iamawesome.net/2009/04/my-geektool-setup/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 19:47:40 +0000</pubDate>
		<dc:creator>conigs</dc:creator>
				<category><![CDATA[Creations]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[desktop]]></category>
		<category><![CDATA[geektool]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[weather]]></category>

		<guid isPermaLink="false">http://iamawesome.net/?p=370</guid>
		<description><![CDATA[
I recently posted my &#8220;April&#8221; desktop on Filckr. Since then I&#8217;ve gotten a few requests for some of the GeekTool code. So here goes…

Let&#8217;s start with the easy stuff.
Calendar

cal
Refresh: 300s, Font: Monaco
Pretty self-explanitory. It just brings up a calendar of the current month
Time

date '+%I:%M %p'
Refresh: 10s, Font: Helvetica Neue
The date command is pretty flexible. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-375" title="geektooldesktop" src="http://iamawesome.net/wp-content/uploads/2009/04/geektooldesktop.jpg" alt="geektooldesktop" width="500" height="313" /><br />
I recently posted my &#8220;April&#8221; desktop on <a href="http://www.flickr.com/photos/31673702@N04/3405525562/">Filckr</a>. Since then I&#8217;ve gotten a few requests for some of the <a href="http://projects.tynsoe.org/en/geektool/">GeekTool</a> code. So here goes…<br />
<span id="more-370"></span><br />
Let&#8217;s start with the easy stuff.</p>
<p><strong>Calendar</strong><br />
<img class="size-full wp-image-380 alignnone" title="cal" src="http://iamawesome.net/wp-content/uploads/2009/04/cal.jpg" alt="cal" width="212" height="148" /><br />
<code>cal</code><br />
<em>Refresh: 300s, Font: Monaco</em><br />
Pretty self-explanitory. It just brings up a calendar of the current month</p>
<p><strong>Time</strong><br />
<img class="alignnone size-full wp-image-385" title="time" src="http://iamawesome.net/wp-content/uploads/2009/04/time.jpg" alt="time" width="221" height="41" /><br />
<code>date '+%I:%M %p'</code><br />
<em>Refresh: 10s, Font: Helvetica Neue</em><br />
The <code>date</code> command is pretty flexible. It&#8217;s used often in my setup. The format string at the end is fairly basic, too. The &#8216;+&#8217; just signifies a user-defined format. %I is hours, %M minutes, and %p is the AM/PM designation. I really wanted to find a way to turn the AM/PM on 90°, but I don&#8217;t think it&#8217;s possible with GeekTool. The single quotes are necessary since there is a space in the format string.</p>
<p><strong>Current Date</strong><br />
<img class="alignnone size-full wp-image-381" title="date" src="http://iamawesome.net/wp-content/uploads/2009/04/date.jpg" alt="date" width="83" height="68" /><br />
<code>date +%d</code><br />
<em>Refresh: 300s, Font: Helvetica Neue</em><br />
Again, <code>date</code> command. %d is the current day of the month.</p>
<p><strong>Current Month</strong><br />
<img class="alignnone size-full wp-image-384" title="month" src="http://iamawesome.net/wp-content/uploads/2009/04/month.jpg" alt="month" width="91" height="38" /><br />
<code>date +%B</code><br />
<em>Refresh: 300s, Font: Helvetica Neue</em><br />
%B &#8211; current month, non-numeric</p>
<p><strong>Day of the Week</strong><br />
<img class="alignnone size-full wp-image-382" title="day" src="http://iamawesome.net/wp-content/uploads/2009/04/day.jpg" alt="day" width="85" height="17" /><br />
<code>date +%A</code><br />
<em>Refresh 300s, Font: Helvetica Neue</em><br />
Self explanitory.</p>
<p>Now the fun parts:<br />
<strong>Current Weather Conditions</strong><br />
<img class="alignnone size-full wp-image-388" title="weather" src="http://iamawesome.net/wp-content/uploads/2009/04/weather.jpg" alt="weather" width="134" height="18" /><br />
<code>curl --silent "http://xml.weather.yahoo.com/forecastrss?p=USWI0455&amp;u=f" | grep -E '(Current Conditions:|F&lt;BR)' | sed -e 's/Current Conditions://' -e 's/&lt;br \/&gt;//' -e 's/&lt;b&gt;//' -e 's/&lt;\/b&gt;//' -e 's/&lt;BR \/&gt;//' -e 's///' -e 's/&lt;\/description&gt;//'</code><br />
<em>Refresh: 1800s, Font: Helvetica Neue</em><br />
That&#8217;s a mouth full. Let&#8217;s take this one piece by piece.<br />
<code>curl</code> will take a url and dump the server response, most often the raw HTML. The &#8216;&#8211;silent&#8217; flag prevents curl from outputting a progress meter or error messages. The url of Yahoo&#8217;s weather page follows in quotes. &#8220;CITYDATA&#8221; should be replaced with your results when you search for your city/zip on their site.<br />
<code>grep</code> is a command line search utility. We&#8217;re basically searching for the part of the XML file that starts with &#8220;Current conditions&#8221; and ends with &#8220;F<br />
<code>sed</code> is basically taking out <code>grep</code> search results and paring it down to just the bit we want: the text of the current conditions.</p>
<p><strong>IP Addresses:</strong><br />
<img class="alignnone size-full wp-image-383" title="ip" src="http://iamawesome.net/wp-content/uploads/2009/04/ip.jpg" alt="ip" width="161" height="55" /><br />
<code>myen0=`ifconfig en0 | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'`<br />
if [ "$myen0" != "" ]<br />
then<br />
echo "$myen0"<br />
else<br />
echo "INACTIVE"<br />
fi<br />
myen1=`ifconfig en1 | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'`<br />
if [ "$myen1" != "" ]<br />
then<br />
echo "$myen1"<br />
else<br />
echo "INACTIVE"<br />
fi<br />
wip=`curl --silent http://checkip.dyndns.org | awk '{print $6}' | cut -f 1 -d "&lt;"`<br />
echo "$wip"</code><br />
<em>Refresh: 60s, Font: Helvetica Neue</em><br />
Yay full-on scripts! In simple words, this pulls the IP addresses from the <code>ifconfig</code> command for each interface (ethernet: en0, airport: en1). The fun bit comes in with the if-then statements. If no IP address is returned, it outputs &#8220;INACTIVE&#8221; instead of just a blank space. It just looks a little nicer. The last bit gets our external IP using curl on dyndns.org.<br />
If you&#8217;re wondering where the labels are in this code (Ethernet, Wireless, External). They&#8217;re in a separate script with <code>echo</code> commands. It was just easier to get the spacing down that way.</p>
<p><strong>Transmit Rate</strong><br />
<img class="alignnone size-full wp-image-386" title="transmitrate" src="http://iamawesome.net/wp-content/uploads/2009/04/transmitrate.jpg" alt="transmitrate" width="177" height="17" /><br />
<code>mytr=`airport -I | awk '/lastTxRate/ {print $2}'`<br />
if [ "$mytr" != "" ]<br />
then<br />
echo "Airport Transmit Rate: $mytr"<br />
fi</code><br />
<em>Refresh: 5s, Font: Helvetica Neue</em><br />
For some reason, my Leopard installation has trouble with keeping the transmit rate up. So I monitor it with this command. Now, by default, the <code>airport</code> command is not readily accessible. We make it that way with the following command in Terminal (found <a href="http://osxdaily.com/2007/01/18/airport-the-little-known-command-line-wireless-utility/">here</a>):<br />
<code>sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport</code><br />
<code>awk</code> is another way of just pulling the info out we need, in this case &#8220;lastTxRate.&#8221; the print $2 command limits the output to the second &#8216;word,&#8217; in this case, the transmit rate in Mbps.</p>
<p><strong>Uptime</strong><br />
<img class="alignnone size-full wp-image-387" title="uptime" src="http://iamawesome.net/wp-content/uploads/2009/04/uptime.jpg" alt="uptime" width="179" height="23" /><br />
<code>uptime | awk '{sub(/[0-9]|user\,|users\,|load/, "", $6); sub(/mins,|min,/, "min", $6); sub(/user\,|users\,/, "", $5); sub(",", "min", $5); sub(":", "h ", $5); sub(/[0-9]/, "", $4); sub(/day,/, " day ", $4); sub(/days,/, " days ", $4); sub(/mins,|min,/, "min", $4); sub("hrs,", "h", $4); sub(":", "h ", $3); sub(",", "min", $3); print "Uptime: " $3$4$5$6}'</code><br />
<em>Refresh: 300s, Font: Helvetica Neue</em><br />
Okay, this one is sloppy. I&#8217;m sure there is a better way to do this, but I just haven&#8217;t found it. The code was cobbled together from this <a href="http://www.unix.com/unix-dummies-questions-answers/74204-geektool.html">forum post</a> and modified to work a little better. But I still get weird output for the first 60 minutes of uptime.<br />
What does this do? <code>uptime</code> displays a few stats, but we&#8217;re just interested in the hours, minutes, and days the computer has been up. Not number of users, etc. So this script just outputs and reformats that bit. All the <code>sub</code> commands substitute one bit of text for another. For example, instead of &#8216;mins&#8217; I just wanted &#8216;min&#8217;, and instead of &#8220;3:42&#8243;, I wanted it to say &#8220;3h 42min.&#8221;<br />
If anyone has any suggestions on how to clean this up or how to stop if from displaying the logged in users during the first 60 minutes (eg &#8220;15min1&#8243;), I&#8217;d love to hear it.</p>
<p>Now, my proudest moment:<br />
<strong>Current Weather Image</strong><br />
<img class="alignnone size-full wp-image-389" title="weatherpic" src="http://iamawesome.net/wp-content/uploads/2009/04/weatherpic.jpg" alt="weatherpic" width="185" height="93" /><br />
Image URL &#8211; PHP script on my server<br />
<em>Refresh: 300s</em><br />
The interesting bit isn&#8217;t in GeekTool, but in the PHP script I wrote:<br />
<code>&lt;?php<br />
$url="http://weather.yahoo.com/forecast/CITYDATA.html"; //Yahoo Weather URL. Sub CITYDATA for your code.</code></p>
<p><code>$divStart = "&lt;div class="\"forecast-icon\"";"&gt;$strEnd = "'); _background-image/* */: none;"; //HTML after weather image<br />
$start = strpos($file_contents, $divStart) + 50;<br />
$end = strpos($file_contents, $strEnd);<br />
$length = $end-$start;</code></p>
<p><code>$imagepath=substr($file_contents, $start , $length); //Pulls path to image<br />
$image=imagecreatefrompng($imagepath); //Pulls image source into PHP<br />
imagealphablending($image, true); //Enable alpha blending (important)<br />
imagesavealpha($image, true); //Applies alpha to image.</code></p>
<p><code>header('Content-Type: image/png'); //Identifies itself as a PNG image<br />
imagepng($image); //Outputs image contents<br />
?&gt;</code><br />
I tried to comment the code as best I can, but basically, it just pulls the raw HTML from Yahoo weather, extracts the image url for current conditions, and spits out that image data as if the script itself were that image. I might be violating some TOS, though, so your mileage may vary.</p>
<p>So that&#8217;s my GeekTool setup. There&#8217;s even more impressive things that people are doing like <a href="http://www.macosxtips.co.uk/index_files/twitter-tweets-on-the-desktop-with-geektool.html">pulling Twitter feeds</a>, so I suggest you hit up <a href="http://www.google.com/search?hl=en&amp;q=geektool+scripts">Google</a>.</p>
<p>UPDATE (2009/04/16): Apparently some people have been having problems with these scripts. Due to the formatting in Wordpress, there may be some new line feeds or line wrapping that is preventing the scripts from working properly. And though I&#8217;ve been pretty thorough, there may be a place or two where it ate some HTML. In any case, I&#8217;m attaching a text file that has all the <a href="http://iamawesome.net/wp-content/uploads/2009/04/gtcommands.txt">shell scripts</a> and another text file with the <a href="http://iamawesome.net/wp-content/uploads/2009/04/weatherimage.txt">PHP</a> (which should be renamed with the .php extension before using)</p>
]]></content:encoded>
			<wfw:commentRss>http://iamawesome.net/2009/04/my-geektool-setup/feed/</wfw:commentRss>
		<slash:comments>66</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.386 seconds -->
