I recently purchased a backlit keyboard that requires Scroll Lock for toggling the lights. I quickly came into some issues that can be worked around with a few simple bash commands - See this thread.

In short, the command I found that fixed this issue was:

xset led named "Scroll Lock"

To enabled Scroll Lock (and turn the lights on), and

xset -led named "Scroll Lock"

To disable Scroll Lock and turn the lights off.

What options are available if I want to issue the former command if a Scroll Lock key event is received and the (Scroll Lock) function is turned off, and the latter in the other case? That is,

    systemCommand('xset -led named "Scroll Lock");
    systemCommand('xset led named "Scroll Lock"`);

Or similar.

I was thinking, at the very least, perhaps doing some sort of a Bash script that kept a variable (if possible) that allowed me to retain the last state of Scroll Lock. I could then execute this script using xbindkeys (which issues commands based on key events input by the user).


Found this after searching for a similar problem. Since it is a year old I might as well answer it anyway.

As in the question if you use xset led named "Scroll Lock" it will enable leds and xset -led named "Scroll Lock" will disable the keyboard leds. If you examine the xset --help it mentions that xset q prints out the current status information.

Here is a truncated sample of the stdout in the terminal:

Keyboard Control:
  auto repeat:  on    key click percent:  0    LED mask:  00000002
  XKB indicators:
    00: Caps Lock:   off    01: Num Lock:    on     02: Scroll Lock: off
    03: Compose:     off    04: Kana:        off    05: Sleep:       off
    06: Suspend:     off    07: Mute:        off    08: Misc:        off
    09: Mail:        off    10: Charging:    off    11: Shift Lock:  off
    12: Group 2:     off    13: Mouse Keys:  off

The string Scroll lock: off will only be present in the output if and only if the Scroll Lock is off, so we can use grep to check for this string. xset q | grep "Scroll Lock: off" works just fine for our purposes. Then, in a shell script we can check for the null string to see when it is on.


result=$(xset q | grep "Scroll Lock: off")
if [ -z "$result" ]; then # Scroll Lock must be on
  echo "Off"
  xset -led named "Scroll Lock"
  echo "On"
  xset led named "Scroll Lock"

Then if you want to, just use your window manager or desktop environment configuration to execute this script when you press scroll lock.


just using bash, U can do this, i use this on a scroll lock backlit keyboard. must be run as root

#!/usr/bin/env bash
if [[ $EUID -ne 0 ]]; then
    echo "this program requires root user" 2>&1
    exit 1

dir1=$(find /sys/devices/ -name brightness | grep scrolllock)
while :
    var1=`cat $dir1`
    if [ $var1 == 0 ] ; then
        echo 1 > $dir1
    sleep 5

I use this in root crontab

@reboot sh ~/sh/backlight.sh &

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.