Detecting Caps Lock from the Linux Command Line

A while back I got a new laptop, a Thinkpad T440s. It has been a wonderful machine, but does have a few small shortcomings – one of which is the lack of a hardware indicator for caps lock status – there are other keys with indicator lights – the mute, mic mute, and function shift keys, but not caps lock – What the heck?

I wanted to fix this to some degree by setting up an on-screen indicator to let me know if caps lock is on. Here’s the script I wound up using to get that data.

v=`xset -q | grep Caps`

echo ${v:7:17}

Save this to a file ending in .sh, apply chmod +x <filename> to make it executable, and you’re good to go. Running this script will generate output that plainly tells you if caps lock is on or not. Next step – integrate it into my status bar.

Leave a Reply