screencapture when screen is dimmed

I have a script that runs every x minutes and checks to see if a particular state exists - if that state exists, then the computer does a screencapture. It works great, however, it appears that if the computer has turned the display to sleep, the screencapture command fires and generates a blank pdf that is 0.8 kb in size.

I was wondering if anyone knows of away to test whether the screen is live before doing the screencapture command.