Binary Clock Geeklet for GeekTool

I've always been fascinated by the binary clock so I made a desktop version that works with GeekTool.  If you haven't played with GeekTool for Mac yet, check it out here.

Edit: One of the downsides to GeekTool is the lack of documentation.  If you're just getting started with it, I just came across this great tutorial to help get you going.

Here is a screen shot of the final product

This geeklet requires ImageMagick so make sure you have that installed first.  If you're not sure how, start by installing MacPorts and then enter this command in terminal.

sudo port install imagemagick

Once you have ImageMagick installed, you need two image files to represent the on and off state of the lights.  These are the two images I'm using in the screen shot above:
Make sure that you save them as .png so the transparency is preserved.  By default the script will look for them in your home directory so just put them there for now.  It really doesn't matter what two images you use, just make sure that both files have the same outer dimensions so the columns line up correctly.  You can change the image location and the image filenames in the CONFIG section of the script.

Now drag a shell script module from GeekTool to the desktop and paste this script in to the command field.

# ======= CONFIG ============================================
# set this to the location of ImageMagick's convert command
# set this to the location where your Image geeklet will look
# set these to the image files you're using for on and off
# do not use '0' or '1' in your image filenames or it will cause confusion in the script below.
# set this to the binary reference you want to use for each number. (0-9)
# the image is designed to reflect time from the bottom up, but
# since the column stack is built from the top down, these numbers may
# appear to be backwards.
    BINARY=("0 0 0 0" "0 0 0 1" "0 0 1 0" "0 0 1 1" "0 1 0 0" "0 1 0 1" "0 1 1 0" "0 1 1 1" "1 0 0 0" "1 0 0 1")
# ===========================================================

hr=$(date '+%I')
min=$(date '+%M')
sec=$(date '+%S')

for index in 1 2 3 4 5 6

$CONVERTER     \( ${col[1]} -append \) \
            \( ${col[2]} -append \) \
            \( ${col[3]} -append \) \
            \( ${col[4]} -append \) \
            \( ${col[5]} -append \) \
            \( ${col[6]} -append \) \
            +append $OUTFILE

Set the shell Geeklet to refresh every 5 seconds or so.  You can have it update more frequently, just be aware of system resources.

Now drag an image module from GeekTool to the desktop and point the url field to the binary_clock_img.png file that should now appear in your home directory.  Set it to update at the same frequency as the shell Geeklet (5 seconds) and then size and position it to taste.

If you find that the binary_clock_img.png file is not being created, check that the CONVERTER file location in the script is set correctly for your ImageMagick installation.  By default, MacPorts will put it in /opt/local/bin/ but it may be in a different spot if you used some other method to install. (e.g. /usr/local/bin/)

Please leave constructive feedback below


No comments:

Post a Comment