You are not logged in.

#1 2018-07-17 17:38:28

PowPaw
Member
Registered: 2018-07-17
Posts: 4

xset led xxx script

Hi guys, I'm running Arch Linux + xfce4 on my machine.
First of all I want to congratulate with every member of this wonderful arch linux forum.
Secondly, I'm going to excuse for any grammar/spelling mistake, since I'm not a native english speaker.
Ok, let's explain my problem. I have a cheap gaming keyboard, the one of the Cooler Master Storm Devastator  kit. Since the 'Scr Lk' key's not working on linux, I'm bound to run the two famous commands 'xset led on' and 'xset led off' from the terminal every time I want to switch on/off my keyboard leds. Now, through the xfce settings I was able to link the 'xset led on' with the 'Scr Lk' button, but I would like to do something more: my dream would be to link 'xset led on' and '... off' both to the same key, so that the first time I press it a '... on' command would be executed, and then, alternatively, 'xset led off' and 'xset led on' again. Is it possible?
Thank you so much!

Offline

#2 2018-07-18 01:05:38

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: xset led xxx script

PowPaw wrote:

First of all I want to congratulate with every member of this wonderful arch linux forum.
...
Secondly, I'm going to excuse for any grammar/spelling mistake, since I'm not a native english speaker.

Thanks, but why? No need to congratulate for anything at this time. Don't worry about your English, I can understand you just fine. smile

For your problem try something like this: https://unix.stackexchange.com/question … y-keyboard Specifically, the bash script they have given. I have modified it slightly. But I am unable to test if this works. Make your own adjustments as needed. Then bind scroll lock to launch this script:

#!/bin/sh

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

From my tests you might need to account for the spaced output from xset q in order to get grep to return the correct value. Play with this and see if it works.


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#3 2018-07-18 01:24:26

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: xset led xxx script

Moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2018-07-18 01:43:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: xset led xxx script

I also cannot test it as I don't have that option in xset, but that script can be much simpler:

xset q | grep -q 'Scroll Lock: *on' && xset led off || xset led on

Most importantly, don't capture the output of grep just to test if it is empty, this is what `grep -q` is for.  Using pseudo-ternary operators rather than a if else block is a style choice.

Last edited by Trilby (2018-07-18 01:45:31)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2018-07-24 21:16:39

PowPaw
Member
Registered: 2018-07-17
Posts: 4

Re: xset led xxx script

Thanks to have answered to my question. Excuse me not to have replied you soon, but I'm on holiday right now smile
On Thursday I'll be at home, so I can play and test the solution of your answers.
I'm going to post what it'll happen.
tongue

Offline

#6 2018-07-26 20:32:11

PowPaw
Member
Registered: 2018-07-17
Posts: 4

Re: xset led xxx script

Ok, I've tried both soltutions, but neither of them worked.
@JohnBobSmith , what do you mean exactly with "Make your own adjustments as needed"?
I'm sorry, but Arch is one of my first linux distros xD
I've known lots of things just by being able to install it, so for me it's already a success. smile

Offline

#7 2018-07-26 20:56:32

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: xset led xxx script

What does it mean that they didn't work?

What is the output of `xset -q`?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2018-07-26 21:02:25

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,843

Re: xset led xxx script

"Does not work" is no useful information.

*How* does it "not work"? Does it fail to activate or deactivate the leds?
Did you try running the commands directly to rule out the shortcut binding failed?
What's the output of "xset q" after "xset led on" and "xset led off"? (There seems to be confusion about using the scroll lock as trigger what lead to the assumption you were controlling the scroll lock LED)

Offline

Board footer

Powered by FluxBB