I finally had that eureka moment, on how to detect Caps Lock using Applescript, while trying to help out on this forum thread about auto-logging out from a Mac.
The Applescript calls KeyboardViewerServer.app, and checks the value of the CAPS key via the Keyboard Viewer window. A return value of 1 means the Caps Lock key is down, and a return of 0 means it's up. The really strange -- but good -- thing is that even if the Keyboard Viewer window is not actually visible, the value still gets returned. (If it pops up the first time you run the script, just close its window). Here's a test script to demonstrate how it works:
Mac OS X Hints
http://hints.macworld.com/article.php?story=20080202094656148