Apple - How can I determine if the screen is asleep in Mountain Lion, from the command line?

Though not directly answering your question this line will give you the time in seconds since the last user interaction which comes from what OS X considers to be an idle user. (independently of screen-savers or black displays.)

echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))

I think I've figured it out. This does it for me:

ioreg -n IODisplayWrangler | grep -i IOPowerManagement | perl -pe 's/^.*DevicePowerState\"=([0-9]+).*$/\1/'

As for the number that this returns, in my case it appears to be in the range of 0-4. I don't know what each number specifically means for sure, but when the display is "on", I get 4, and when the display has been put to sleep by idle I get 0. I assume the in-between states are for dimming, etc, but I don't have a laptop here, so I'm not sure.