PCs

Get system display options with GeekTool for the Mac

Vincent Danen introduces GeekTool, a System Preference Pane for Mac OS X that allows you to display system information of your choice directly on the desktop.

Vincent Danen introduces GeekTool, a System Preference Pane for Mac OS X that allows you to display system information of your choice directly on the desktop.

---------------------------------------------------------------------------------------

GeekTool is a fantastic System Preference Pane for Mac OS X that allows you to display a variety of different pieces of information directly on the desktop. It comes with three modules: the file plugin, the shell plugin, and the image plugin. These can be used to display or tail the contents of files on the desktop (think log files), the output of shell scripts, and image graphics (like RRD or MRTG graphs), respectively.

For a lot of people, GeekTool may be nothing more than a novelty, but for system administrators and others, GeekTool can be a real boon. The real power in GeekTool is displaying output from shell scripts, which makes the "Geek" in GeekTool apt for many.

Once the Preference Pane is installed, you can create a new "Geeklet" by dragging one of the icons to your desktop. As an illustration, we'll create a Geeklet that displays the computer's internal and external IP addresses.

Drag the Shell icon to the desktop. An empty box will appear and a Properties window will show up. Drag the box to to the location on the desktop where you want it to be displayed. You can move it around, resize it, and adjust the properties at this point. In the Command section of the Properties, we want to give it the path to a shell script to execute. Now open the Terminal and find a place to create your shell script. I store my GeekTool scripts in ~/bin/gt-scripts/. Create a new file called gt-ipinfo.sh in this directory with the following contents:

#!/bin/sh
external=$(curl -s www.whatismyip.com/automation/n09230945.asp | awk {'print $1'})
internal0=$(ifconfig en0 | grep "inet" | grep -v 127.0.0.1 | grep -v inet6 | cut -d ' ' -f 2)
internal1=$(ifconfig en1 | grep "inet" | grep -v 127.0.0.1 | grep -v inet6 | cut -d ' ' -f 2)
echo "External : ${external}"
if [ "${internal0}" != "" ]; then
    echo "Ethernet : ${internal0}"
fi
if [ "${internal1}" != "" ]; then
    echo "Ethernet : ${internal1}"
fi

Next, make the script executable and test it by executing:

$ chmod a+x gt-ipinfo.sh
./gt-ipinfo.sh
External : 1.2.3.4
Ethernet : 192.168.1.50

The script simply displays the external IP (obtained from whatismyip.com) and the IP(s) assigned to the computer on the local network.

Switch back to GeekTool and in the Command field enter: /Users/[user]/bin/gt-scripts/gt-ipinfo.sh or the full path to where this script lives. Change the Refresh Every option to something like 600 to run the script every 10 minutes. With a script like this, you could set it to 3600 to run every hour as this information should not change often. Within the Geeklet square on the desktop, you should see this information now.

You can set a background color and opacity, change the text font and color, and whatever else you want in order to customize the text to your preference. Resize the window to make sure all of the text is visible. The Keep On Top checkbox is handy as it will cause the output of the Geeklet to float over any windows that also occupy that space on the desktop.

This is a pretty simplistic example of what you can do with GeekTool. A number of scripts and examples are available online, including my own that allow you to keep an eye on uptime/CPU/RAM usage, current weather conditions, and even upcoming items from The Hit List. Look at http://linsec.ca/GeekTool for more examples and scripts.

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

0 comments