Check if caps lock on in terminal
There is a great command line code written by Stefenk on Macscripter 

Stefen's code allows you to detect for cmd, option, control, shift, and caps lock.

In his post he provides the code and a download zip of it.

You can either download it or build your own in Xcode using foundation project.

I just tested both ways in El Capitan and they both work.

The code if you want to build your own in Xcode.app is:

#import &lt;Carbon/Carbon.h&gt;

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        unsigned int modifiers = GetCurrentKeyModifiers();
        if (argc == 1)
            printf("%d\n", modifiers);
        else {
            int i, result = 1;
            for (i = 1; i &lt; argc; ++i) {
                if (0 == strcmp(argv[i], "shift"))
                    result = result &amp;&amp; (modifiers &amp; shiftKey);
                else if (0 == strcmp(argv[i], "option"))
                    result = result &amp;&amp; (modifiers &amp; optionKey);
                else if (0 == strcmp(argv[i], "cmd"))
                    result = result &amp;&amp; (modifiers &amp; cmdKey);
                else if (0 == strcmp(argv[i], "control"))
                    result = result &amp;&amp; (modifiers &amp; controlKey);
                else if (0 == strcmp(argv[i], "capslock"))
                    result = result &amp;&amp; (modifiers &amp; alphaLock);
            }
            printf("%d\n", result);
        }
    }
    return 0;
}


----------( update ->

If you want to compile it from Terminal.app

Put the code into a plain text file. I just used TextEdit.app and a Plain text document.

cd to the same directory as your file.  Make sure that the extension is .m ( .c will be ok also)

Then Run.

gcc  -framework Carbon CheckModKeys.m -o CheckModKeys


CheckModKeys.m is your file.

CheckModKeys  is the name of the app to be outputted.

&lt;-)



To detect caps lock your command would look something like:

/Users/UserName/MyFolder/CheckModKeys  capslock


a 1 or 0 will be returned.

1 for on

0 for off



All credit goes to Stefen. I just remembered he posted this way back in`2009. And it still works today..