Now, wait a second:

There was a time where programming in Java was funnier than it is today.

Back in 1997 I published in my own web page my first Java applet. It was a calculator. That was way cool; I was able to share with the visitors of my site a whole program: not only the source code, but the whole thing, working, available for anyone to use, no matter the browser, no matter the platform, no matter whe geographical location.

You can play with that applet here. It still works on my MacBook and on my G5, almost 10 years later, running under the Java 1.5 virtual machine. I am simply amazed (It might not be the most interesting code you’ll ever see, nor the most beautifully architectured one, but it did what I wanted it to do… so I consider it a success. Thankfully I see things different now).

So there was a time were Java was cool, new, easy to learn, the way to go. And here’s a story to show how cool it was. Continue reading

How to Grab (or Capture) your Screen with Cocoa?

Lately I got curious to know how could I grab the entire desktop of my computer, and save it into a file, or display it into an NSImageView component. I started to look around on the web and discovered that:

  • There’s no direct support for that in Cocoa
  • There’s a lot of different ways to do it, both supported and unsupported, cross-processor and not, easy and complicated

I have found several useful resources in my quest, like this one, this other one, and finally this one. But what I wanted most was a complete application to play with, so what I did is to put all the different implementations I’ve found in one single application, called “ScreenshotDemo”:

Amazingly, the approach that seems the ugliest turned to be the most appropriate, that is, using an NSTask instance wrapping the /usr/sbin/screencapture utility. With it, the application feels lighter, easier to maintain, in the true, purest Unix style: using a collection of small utilities, all chained one to the other, is better than having an overbloated tool that does everything, but just bad.

You can just download the (universal) binaries and the source code from the ScreenshotDemo Project page.

By the way, for those that would like to do the same in C#, like me :) just check out this code. It isn’t much easier in .NET, as you can see ;)

And last but not least, here’s how to do it in wxWidgets, explained by Julian Smart, the creator of this incredible library.