macfidelity

|

rethinking the think-different thing

mac | Using Geektool to display comics (xkcd) on your Mac OS X Desktop

March 22nd, 2009 at 2:00

20090322_geektool_comics_14

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.

20090322_geektool_comics_01

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.

20090322_geektool_comics_02

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.

20090322_geektool_comics_03

Navigate to the Strips tab and select your comic-sources

20090322_geektool_comics_04

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.

20090322_geektool_comics_06

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.

20090322_geektool_comics_09

2. Create our select-a-random-image-and-copy-it script and save it as selectRandomImage.sh in our folder comic_test.

20090322_geektool_comics_07

The folder comic_test should look like this now:

20090322_geektool_comics_10

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

20090322_geektool_comics_08

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

20090322_geektool_comics_11

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.

20090322_geektool_comics_12

Et voila

20090322_geektool_comics_13

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: , , , , , , ,

28 Responses to “mac | Using Geektool to display comics (xkcd) on your Mac OS X Desktop”

  1. Kruemel^Nico Says:

    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

  2. fidel Says:

    hehe – absolut recht.

    Ich dachte mir beim schreiben nur: verfolge das KISS-Prinzip
    -> http://de.wikipedia.org/wiki/KISS-Prinzip

  3. Krueme1^Nico Says:

    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

  4. fidel Says:

    Ja cool – hau rein – ich editier das ganze dann gerne noch nachträglich in den Beitrag rein wenn dein Script fertig ist ;)

    Gruss
    fidel

  5. edwford Says:

    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 =)

  6. fidel Says:

    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

  7. Chris Says:

    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!

  8. Arvindh S. Says:

    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!

  9. fidel Says:

    @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 ;)

  10. Customize Your Mac Desktop « raxcy Says:

    [...] [...]

  11. Zeto Says:

    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

  12. fidel Says:

    @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

  13. Geektool, quick and dirty way for rotati… « pxldskblg Says:

    [...] 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/ [...]

  14. Bob Says:

    I copied your script exactly and I’m getting an error in line 24…

    8812 % 0: division by 0 (error token is “0″)

    :-(

  15. fidel Says:

    @Bob
    please double-check the script

    Best Regards
    fidel

  16. » Minimalism and the Mac pt 1. :kyle doherty Says:

    [...] Displaying a random Comic Image on your desktop –  via macfidelity.de [...]

  17. IAN Says:

    Hey, when I run the script to make the a.png file, it doesn’t show up. Help please and thank you in advance!

  18. edwford Says:

    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 =)

  19. Adrian Says:

    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

  20. fidel Says:

    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

  21. Adrian Says:

    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

  22. fidel Says:

    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.

  23. Adrian Says:

    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

  24. fidel Says:

    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

  25. Mega Roundup of Geektool scripts + inspiration gallery. – Your source of inspiration – Francesco Mugnai Says:

    [...] Using Geektool to display comics (xkcd) [...]

  26. Dylan Thompson Says:

    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.

  27. Adam Says:

    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!

  28. How to GeekTool your Mac to Awesomeness Says:

    [...] GeekTool to add an xkcd comic on your [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>