Caps Lock Query/Set in AS/OSX

Does anyone have a snippet to query and/or set the “Caps Lock” state in AS/OSX?

You can use “keys pressed”, from Jon’s Commands, and it will throw {“Caps Lock”} if such is pressed. But I don’t know if you can “press” it using one of “System Events” or “Extra Suites”… :?:

What I’m trying to do is poll the state of the “Caps Lock” key. It might work to use “keys pressed” but without the matching poke, it falls down. Ultimately I’m trying to create AS that will allow temporary defeating of the Caps Lock key, albeit I will probably use the utility most of the time, but I would prefer not to defeat it entirely as in the OS9 hack at ResExcellence. And that was for OS9 only, I think?!?

I try also to poll the state of the “Caps Lock” key.

Jon’s Commands don’t work in Intel.

This seems to work in Leopard/Intel:

tell application "System Events"
	tell application "KeyboardViewerServer" to activate
	set CAPS to (get value of checkbox "⇪" of window 1 of application process "KeyboardViewerServer") as number
end tell

For the full explanation of the caps lock script see 10.5: Use Caps Lock to send keystrokes via AppleScript and where to find the “KeyboardViewerServer” (see comments on the link)