Geeking out with GeekTool (a desktop show and tell)

It’s quite shameful that I only discovered this amazing, squee-worthy app now. GeekTool is very aptly named, and is a great app for those who love tinkering about with their UI and workspaces. It allows you to put almost anything on your Mac’s desktop and stay out of your way. There’s no accidental drags, just plain ol’ background goodness.

Well, I certainly didn’t lose any time setting mine up. It’s always a work in progress–I have a few more ideas that I want to do at some point–but this one works wonders for me.

I’ve noted relevant areas in the Flickr page, but in a nutshell, I have the current date and time on the upper left, along with my machine’s uptime, a calendar for the current month, and events for the next seven days from iCal. I have the currently-playing album/track below that (using Bowtie), my computer’s network status, a check for if my website is up and the ping time to the server, and then my machine’s CPU and memory usage as well as relevant processes.

On the right is my Adium contact list window set as a borderless window, and various desktop shortcuts for the connected drives etc. All files saved to the desktop automatically (like screen shots, or stuff I accidentally save there) are moved automatically by Hazel to one of the three folders (Images, Documents, or Miscellaneous); Hazel will also label the folder red if it reaches a certain size (“clean this folder up omg!”).

The setup

First, a disclaimer: I have no idea why, but when I imported my Geeklets to my office machine, the more complicated shell scripts (like, showing more than the current date) ceased to work. This may be a mix of differences in output and other environmental factors; so you may also need to fiddle with the scripts as you use them.

To create a new geeklet, once you have GeekTool installed, go to the GeekTool preference pane (in System Preferences) and select one of the Geeklet icons and drag it to your desktop. My Geeklets all use the Shell Geeklet type.

GeekTool preference pane

Settings will show up in the Geeklet settings window, which you can tweak to your liking. The commands I print out here will go in the Command field of that window, and then you can tweak with the fonts and colors and placement to your heart’s content.

Date, time, machine uptime and events

Date, time, machine uptime and calendar eventsThe simplest command here would be the cal command, for the calendar; you should use a fixed-width font for this Geeklet to line up the columns nicely according to the weeks, or else it will probably confuse you…unless you just want it pretty-like and don’t actually need a usable calendar on your desktop ;)

The next ones would be the actual date. Each of the text (February, 03, Thu, 10:28) are separate Geeklets, although you can certainly combine them if you like. I used separate Geeklets in order to order them the way I wished, as you can see. It’s quite simple–the command is date, plus some parameters.

Month (long) date +"%B"
Day of month date +%d
Day of week (short) date +%a
Time (24-hour format) date "+%H:%M"

Uptime is a little more complicated, but it’s basically using the uptime command. I was able to find a couple commands online for machine uptime, but I discovered that once my machine was up more than a day, the actual text did not make any more sense. The actual uptime output for more than a day would be something like:

14:04  up 1 day, 19:25, 2 users, load averages: 2.46 1.84 1.20

But for less than a day, it would be

14:04  up 19:25, 2 users, load averages: 2.46 1.84 1.20

So you can see, I couldn’t rely on the order of the output (delimited by spaces). I set out to do it my way:

uptime | cut -c 11-100 | awk '{split($0, a, "[ mins]*, [1234567890]+ user"); sub(":", "h ", a[1]); sub(" day,  ", "d ", a[1]); print "Up for " a[1] "min"}'

If the above doesn’t work for your machine, you can try fiddling with the command output. What I did up there was to cut the uptime command from to the 11th character (which should be just after the “up” portion) to an arbitrary character position (100…I don’t think my machine will ever be up enough to warrant any longer uptime text); then split the output to two strings using “, [number] users” as the delimiter (where to split, basically); that would result in something like 19:25 or 1 day, 19:25. The rest is just cosmetic substitution (day to d, : to h, addition of min).

The events make use of another script–icalBuddy. It basically gives you a command to run in Terminal to output the contents of your iCal into text output. After installing icalBuddy and making sure that the icalBuddy binary/command is accessible by your system, you can simply run:

icalBuddy -nrd -df "%a" -tf "%H:%M" -nc -eed -ps "| - |" -iep "datetime,title" eventsToday+7

And you have your weekly events :)

Network status

GeekTool network settingsI wish I was cool enough to have done this myself, but I’m not ;) Here is a good post that explains how to do it–along with other Geeklet ideas!

My website check and ping time display I was able to get from somewhere online as well, but I can’t seem to find it anymore. I love it for quick checks to see if my website is actually up and how it’s doing:

GeekTool website check

Very simply, for the website check itself, this is the command I use:

curl -s | perl -nle 'print for m:<title>(.*)</title>:'

It basically gets the title of the website ( in this case, replace this with whatever website URL you like) and prints it out, so if something funny happens to the index page, the display will also be wrong. The green button is simply a Geeklet setting to display status feedback image.

The ping time is a separate Geeklet, again taken somewhere online, but slightly modified so I can plug in any URL as a parameter. Create a shell script somewhere (via vim, TextMate, TextEdit, whatever you like) and put this in:

#! /bin/bash
PING=`ping -q -c 1 $HOST`
if [[ $? -eq 0 ]] ; then
TIME=`echo $PING |tail -1 | cut -d/ -f 5`
echo ${TIME}ms #away from $HOST
exit 0
echo $HOST could not be reached
exit 2

And to have GeekTool run it, in the command field just put in:

source /path/to/file

(You can also just make it executable so you won’t need to use source.)

CPU, memory and processes

This one was particularly thorny when I moved it over to my office machine (I’ve yet to fix it there; no time) so take it with a grain of salt. There are many similar blog posts containing the use of top and ps and whatnot with this same information, but for this one I’ve kind of fiddled around with it quite a bit using a lot of the man command ;) and trial and error.

GeekTool CPU and memory usage and processesI wanted to have the CPU and memory usage available, as you can see in the first two lines. They’re relatively simple with the use of top. For CPU usage:

top -l 2 | awk '/CPU usage/ &amp;&amp; NR &gt; 5 {print $6, $7="usage:  ", $8, $9="user,", $10, $11="sys,", $12, $13}';

For memory usage:

top -l 1 | awk '/PhysMem/ {print "RAM in use: ", $8, $9, $10, $11, " \n"}';

(For my office machine, I had to fiddle with the order of the output, going from $6, $7 etc to $1 and $2…so you may want to check that out if it doesn’t work for you.)

For the processes, I’m using:

top -orsize -FR -l2 | grep '^....[1234567890|PID] ' | grep -v ' 0.0% ..:' | cut -c 1-24,33-42,64-77 | sed "1 d"

I order it via resident memory size (so highest memory hoggers are first on the list) but those with 0% CPU usage at the time the command is run is not shown. Two samples are shown to get the CPU usage, and the extra table header line (since there are essentially two tables in the output) is removed from the top at the last.

For all three, I just chain them together under one Geeklet so that they all line up together, since I didn’t really need to move them all around separately.

Other ideas

There is plenty one can do with GeekTool–I’ve been thinking of showing a text file containing vim shortcuts, for example, so that I can easily familiarize myself with it; or use GeekTool to go through a couple nice photos in a directory and refresh every so often. I had a to do Geeklet using icalBuddy, which I’ve removed; I also had my apache error log on my desktop, but I decided it wasn’t too pretty to have error logs on a desktop ;)

Here are more useful GeekTool tutorials and blog posts:

Have fun!

Next Page »