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 =)
October 27th, 2010 at 08:30
Hi,
Does anyone know how I could do something similar with text quotes? Over the years, I have collected a number of quotes I like but I never go over them. It would be nice to have just a new random quote on my desktop.
Your suggestions would be very much appreciated.
Adrian
October 27th, 2010 at 10:29
Adrian:
i dont see any problem in that quote-task.
basically it depends on your source – is it a single file containing all quotes or file-per-quote.
In case of a single file you would need a script to grab a random line – in case of several files you need to select a random file.
How ask yourself what kind of script-language you prefer
Hope that short comment helped already.
Best regards
fidel
October 27th, 2010 at 10:48
Hi Fidel,
Thanks for your reply. Unfortunately, I have no idea how to write a script. How can I do that? Is there a template I can modify? Or where can I find more information to learn more about writing scripts?
It doesn’t matter whether the script is for several files or one long file with many lines. I’d prefer whatever is easier to do.
Regards,
Adrian
October 27th, 2010 at 15:21
Hi Adrian,
first off all – i closed this blog several month ago -so dont expect new content or similar …just to clear things at the beginning.
regarding your idea
##
If you arent into scripting languages it might be hard to finish … scripting languages differ heavily and usually it’s just about personal preference.
I guess you could easily use the script above and modify it for your idea. At the ends its just about selecting a random file (in my case an image – in your case a text file) copying that to a specific folder with a FIX name …and let geektool display that file.
The random script delivers new random files with the same name at the defined place ….
So – if you are new to the entire scripting thing – consider modifiying the idea mentioned in this blog-post. In that case you would need a single file for each quote. Then replace the image specific part of the script with your .extension and you should be almost done.
Good luck & best regards
fidel
I hope that helps.
October 31st, 2010 at 23:45
Hi Fidel,
Many thanks for your suggestion. Although I don’t understand the $ ” l ! language, I can follow the logic. However, the script doesn’t work, not even for the jpg-version. The random picture (or quote) never appears in the respective folder.
I triple-checked the code and the paths. I used AppleScript Editor to write the script. Could that be the problem? The refresh rate in Geektool is 1s. Is there anything else I need to activate or deactivate in Geektool to make this first part work?
Adrian
November 2nd, 2010 at 10:35
Hi Adrian,
the first script is a bash-script (#!/bin/bash) …why AppleScript-Editor is most likely “not the best thing” to use
. To be honest … you shouldnt use AS-Editor for anything else besides AppleScript Code
Use any REAL texteditor (which excludes TextEdit as well) and see if that helps.
Best regards
fidel
November 8th, 2010 at 19:36
[...] Using Geektool to display comics (xkcd) [...]
September 4th, 2011 at 01:48
GeekTool 3.3.0 offers an option to select a directory for the pictures, and to choose a random picture from there. Much simpler than the bash scripting required for this method.
However this article does introduce some interesting and fundamental ideas about the power of GeekTool, and gives us a glimpse into the power of what one could do with it.
Bravo.
September 24th, 2011 at 01:39
With the new geek tool on lion, it’s a lot simpler. You still have to download iStrip and follow all of the steps involving it, however if you create a new image process in geek tool, you can actually reference your cache directly and tell geek tool to pick a random image for you, thus getting rid of the messy coding steps. It also enables you to randomly cycle through more comics than just xkcd!
December 25th, 2011 at 10:53
[...] GeekTool to add an xkcd comic on your [...]