mac | Using Geektool to display comics (xkcd) on your Mac OS X Desktop
March 22nd, 2009 at 2:00
Some days ago i was wondering how to display random comic strips on my Mac OS X Desktop.
Before we’re getting started a short warning:
The following solution is far away from perfect and somehow “dirty”
But who cares about perfect … it’s about getting it done
As a big fan of Geektool it is pretty clear that i want to use its Picture function to display the comic strip on the desktop. Unfortunaly Geektool can only handle a full image path – so we can NOT work with wildcards
So we have the following tasks
- Download selected comic strips from an online source – for sure automated
- Select random image – using a simple .sh script executed using Geektool
- Display random image – using the picture function of Geektool
Ready ?
Download material
A simple way to get tons of comic strips in mind ? For sure we could write some fancy script which downloads from random sources but there are other solutions =)
I used iStrip – an application which is designed as comic-viewer. iStrip offers a nice interface to select from a huge list of comic strips and is able to download (they call it caching) those selected comic-strips.

So basically we just need to install iStrip, select the sources we want to use and enable the caching feature which should save enough material to our local folder.
1. Install iStrip
2. Create a folder which will be later used as storage location for the images. I use a folder called “comic_test” on my Desktop.

3. Run iStrip and open the Preferences window. Navigate to the Cache tab and enable Cache images locally. You can define the amount of images – i suggest as much as possible cause it will prevent us from running iStrip each day to get new strips.

Navigate to the Strips tab and select your comic-sources

After pressing enable you should take a look on the defined comic-storage location. In my case it worked already and i have enough testing material. The subfolder com.xkcd was generated by the caching function of iStrip.

So … we got strips – task 1 solved.
Select random image
In step 2 we need to select a random image of our new folder “comic_test”. As we want to perform this random-select periodically we need a small script.
1. Create a new subfolder _myRandomImage in the folder comic_test.

2. Create our select-a-random-image-and-copy-it script and save it as selectRandomImage.sh in our folder comic_test.
The folder comic_test should look like this now:

Now we need to execute our script selectRandomImage.sh periodically using Geektool

As a result we have a new image a.png in our targetfolder /comic_test/_myrandomImage/

Ok … lets jump to the last task
Display random image
The final step is pretty easy, just create a new task in Geektool to display our random image a.png on your desktop.

Et voila

As mentioned at the beginning: ugly as hell – but it works. I hope you enjoy your comic-strip’ed-desktop
I guess based on this initial idea you can easily write some more enhanced scripts to modify the behaviour.
Best regards
fidel
Tags: comic, comic-strips, desktop, geektool, image, istrip, random, xkcd




March 25th, 2009 at 01:47
nice nice, aber wo ich gerade iStrip an hab frag ich mich warum du hier nur xkcd an hast ich finde in die auswahl gehört eindeutlich auch NICHT LUSTIG xD
March 25th, 2009 at 08:22
hehe – absolut recht.
Ich dachte mir beim schreiben nur: verfolge das KISS-Prinzip
-> http://de.wikipedia.org/wiki/KISS-Prinzip
March 25th, 2009 at 15:07
Ich erweitere am besten heute abend mal dein shell script …
sollte sicher gehen die Ordner davor auch random zu öffnen …
Wobei man noch einbauen muss, dass der checkt welche ändung die Bilder haben. Bei NL sind es jpg datein. Laut deinem hier bei xkcd png.
mal sehen mal sehen
March 25th, 2009 at 15:27
Ja cool – hau rein – ich editier das ganze dann gerne noch nachträglich in den Beitrag rein wenn dein Script fertig ist
Gruss
fidel
May 27th, 2009 at 00:43
Thankyou very much for this. I posted a thread on the XKCD forums trying to get XKCD to display on my desktop, but I couldn’t think of a way to go about it. Thanks again =)
May 27th, 2009 at 11:39
Hi edwford,
i think while searching for an solution i even discovered your forum-post there
Great that you found the solution now here.
Let me know if you have other geektool-tasks in mind hehe
Best regards
fidel
June 4th, 2009 at 06:48
Hey, that’s about the neatest GeekTool tip I’ve seen so far! However, I was stuck for hours on making the shell script work. Turned out that I had written hyphens (-) instead of equation marks (=) in the “select and copy” line. Felt a bit stupid afterwards. Take heed, all else who follow this wonderful tutorial!
June 7th, 2009 at 06:55
Hey!
I tried copying the code into a text file and then doing chmod 744 on the file. However, it always turns up an error about unexpected EOF while looking for matching ‘ ” ‘
Honestly, I could not find any difference!
Here’s my code. Help please!
CODE BEGINS
#! /bin/bash
sp=/Users/Icarus/isc/test
tp=/Users/Icarus/isc/dest
ext=’JPG’
find -E “$sp” -iregex “.*.($ext)” |
(
i=0; while read line; do lines[i++]=”$line”; done
cp “${lines[$RANDOM % $i]}” “$tp/a.$ext”
)
CODE ENDS
Edit: Solved it! Magnifying helps!
P.S. I’m leaving the corrected code above. It’ll be easier to copy!
June 7th, 2009 at 12:01
@Chris
sorry for the confusion.
I made bad experiences pasting code into wordpress as it seems sometimes some special-characters get lost …. that’s why i just used screenshots.
Great to hear you managed it finally
@Arvindh
a click on the shell-script image should now bring a slightly bigger version of the screenshot.
… sorry for the time and effort
June 10th, 2009 at 19:37
[...] [...]
July 30th, 2009 at 05:39
Hi fidel,
I’ve been having trouble writing the shell script for geektool to chose a random image, what program did you use to write the shell script, if possible could you break down how to write the script exactly?
Thanks,
Zeto
July 30th, 2009 at 12:25
@Zeto:
hi
…. basically the text-editor you use shouldn’t matter at all – i was using Smultron (http://smultron.sourceforge.net/) in the image above.
If you open the image above in an image-viewer and zoom in it should be easy for you to reproduce the code.
If that doesn’t works feel free to ask again and i’ll see what else i can do
Best regards
fidel
January 17th, 2010 at 16:42
[...] Geektool, quick and dirty way for rotating random image on desktop: http://macfidelity.de/2009/03/22/mac-using-geektool-to-display-comics-on-your-mac-os-x-desktop/ [...]
February 6th, 2010 at 04:29
I copied your script exactly and I’m getting an error in line 24…
8812 % 0: division by 0 (error token is “0″)
February 6th, 2010 at 08:39
@Bob
please double-check the script
Best Regards
fidel
February 16th, 2010 at 17:40
[...] Displaying a random Comic Image on your desktop – via macfidelity.de [...]
June 26th, 2010 at 05:49
Hey, when I run the script to make the a.png file, it doesn’t show up. Help please and thank you in advance!
June 27th, 2010 at 11:59
Hey again, just want to say a simpler way to achieve this is now possible, assuming you are using geektool 3. ^_^ http://www.macosxtips.co.uk/geeklets/images/show-latest-xkcd-comic-with-alt-text/
Also alt-text =)