Scripting Script - find area of white pixels on row?

I've automated a job I have to do frequently. They are puzzles for the newspaper, which are always the same width, but vary in depth. My AppleScript finds the large number of white pixels in a row of pixels, which indicates the bottom of the puzzle. It's a crazy kluge.

What I have is an AppleScript I wrote that uses DigitalColor Meter (Macintosh) to copy the values of the pixels under the cursor's current location which I have ascending up from the bottom of an image by 4 pixels at a time in a repeat loop. It finds a white pixel and increments the variable (i). If the variable is up to 30, the cursor clicks and selects a single pixel which I can get the location of so that I have coordinates for a crop.

What I want is a Javascript that will do the job much, much faster and more reliably. Does anyone have ideas? I have only worked in AppleScript at this point. I'd like to get into JavaScript for Photoshop too.