Here's an AppleScript, found in the thread Programmatically Toggle the Caps Lock Key, that checks the capslock status, and returns a 1
if it is ON and a 0
if it is OFF:
use framework "Foundation"
use framework "AppKit" -- for NSEvent
property NSCapsLockMask : a reference to 65536
property NSEvent : a reference to current application's NSEvent
set KeyFlags to NSEvent's modifierFlags() as integer
if ((KeyFlags div NSCapsLockMask) mod 2) is not 0 then
return 1
else
return 0
end if