sizeof.io

Snap webcam photos whenever your app crashes

I decided to try something even funnier with capturing your expressions when developing applications.

What is your expression when your application borks out and throws an exception? Let's see!

To start, we do what we did in the first article: Install the imagesnap library from homebrew:

brew install imagesnap

And once that's done, we do something a bit different in our Xcode project. We won't be adding a Run Script build phase, but instead a custom exception breakpoint to capture our photo.

Once your project is open, navigate to the breakpoints sidebar menu on the left, and add a new Exception Breakpoint breakpoint by clicking on the + icon on the bottom left.

Adding the breakpoint

Set the added breakpoint to only capture Objective-C exceptions, and optionally to continue evaluation after the breakpoint is reached.

Change the Action menu to AppleScript, and put the following text into the script box:

set photoPath to "~/Pictures/BuildPhotos/$(date +%y%m%d%H%M%S).png"
do shell script "/usr/local/bin/imagesnap " & photoPath

Note: If you installed imagesnap somewhere else, or have your own folder for the photos, be sure to change the paths in the script, or it just won't work.

The breakpoint should now look something like this:

Finished breakpoint

To test the capturing, you can add two lines to our AppDelegate (or any file you want, really) to trigger an objective-c exception, in this case an index out of bounds exception:

    NSArray *array = @[@"WHY", @"SO", @"SERIOUS"];
    NSLog(@"%@", array[9001]);

Run your app. Smile for the camera. And you're done!

God damnit