Geektool Scripts



Geektool scripts geeklets

Implementing the Script as a Geeklet. Once you're finished coding, save out this script in your Geeklets folder. Now go back to GeekTool and drag out a new shell Geeklet. In the Command field, type 'osascript' followed by a space and the path to wherever you place the script. Here's what my command looks like. AppleScript has been introduced in GeekTool because some users wanted to extend possibilities in ways that could not be implemented directly into the software. That's why it is a very powerful tool that will let you go far beyond the standard features of GeekTool. The structure of scriptability in GeekTool is quite simple. I want to run a Ruby script in Geektool that refreshes every 3 hours (so I set the refresh rate to 10,800 seconds) and the shell command in Geektool has this code in it: ruby '/file.rb' The file is located at root for convenience. GeekTool is a great application for OS X that allows you to display the contents of shell scripts, images, and files directly on the desktop. This page provides some scripts that I have written or adapted from others I've found to provide useful information on the desktop with GeekTool.

awk '{printf('%.2f%%', $10/$5 * 100)}'

This first awk command reads the standard input, one line at a time (if necessary; I'm guessing only one line is being sent to it here), and splits the line into columns, the data in column c having the name $c. (So $5 is the 5th column's data and $10 is the 10th column's). The printf command calculates $10/$5*100 (that is, the 10th column divided by the 5th column, times 100) and prints it as a floating-point number with 2 decimal places ('%.2f') followed by a percentage sign ('%%').

Best Geektool Scripts

awk '$3~/Capacity/ {c[$3]=$5} END{OFMT='%.2f%%'; max=c['MaxCapacity']; print(max>0?100*c['CurrentCapacity']/max:'?')}'

This awk command starts by reading in each line of ioreg -l, one at a time. Whenever column 3 ($3) contains the word 'Capacity' ($3~/Capacity), it runs the command 'c[$3]=$5', which stores the fifth column into an array (a box) labelled with the contents of the third column. (Unlike in some languages, awk's arrays can be labelled with text, not just numbers.)

Best Geektool Scripts

The END segment means to run the following command after you're done reading in standard input. First it sets OFMT='%.2f%%', which means to change the output format so that it outputs real numbers with two decimal places followed by a percentage sign (as above). Second, it defines the variable max to be the contents of the array labelled 'MaxCapacity' (which was defined in the first part of the process). Next it prints out the result of the formula max>0? 100*c['CurrentCapacity']/max: '?' which is an if-then statement (with the form test?true:false; awk stole this notation from C). If the variable max is greater than zero, then take the contents of the array labelled 'CurrentCapacity', divide it by max, and multiply by 100. If max is not greater than zero, then something wrong happened (maybe ioreg doesn't have a line which says 'MaxCapacity') and so return the character '?'.

Best geektool scripts

Geektool Scripts Geeklets

Type 'man awk' in the terminal for a full description of the command. It's basically a full-blown programming language, designed to deal with text files one line at a time, and it's really useful; it's also something you can pick up a little bit at a time, if you're so inclined.