• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root [MOD][SCRIPT] Enable/Disable soft key LEDS *6/14/12*

See you may have just started like me, but you have more past experience in the game lol. I appreciate how much you have helped as well as superuser!

Not a problem at all, brother. We're all here to help one another, and anything I can do to contribute to that effort is what will get done.
I'm not just learning for the community, I'm learning for myself; but I've always been a huge fan of "open source."
 
Upvote 0
Not a problem at all, brother. We're all here to help one another, and anything I can do to contribute to that effort is what will get done.
I'm not just learning for the community, I'm learning for myself; but I've always been a huge fan of "open source."

Well said! Now that we have it in a single widget toggle. Wee need to maybe add it to the power menu lol
 
Upvote 0
This is what i've done so far,

Code:
#!/system/bin/sh
if >/sys/class/leds/button-backlight/max_brightness
then
/system/etc/init.d/LEDsON
else
/system/etc/init.d/LEDsOFF
fi

i already had the scripts for on and off within init.d (LEDsON and LEDsOFF) and both work so i used commands to call them in this toggle script, but what i cant get to work is a way to read the value of 'max_brightness', whether is is 0 or 15. i've used the -eq but i get '-eq' not found , or 0 not found, etc, ive used brakets and those dont get found either, anyone can help?

in reality i dont know what code to use to open max_brightness and for the script to read the number inside of it, and this is the most important part of the conditional script, w/o it the toggle wont work.
 
Upvote 0
This is what i've done so far,

Code:
#!/system/bin/sh
if >/sys/class/leds/button-backlight/max_brightness
then
/system/etc/init.d/LEDsON
else
/system/etc/init.d/LEDsOFF
fi

i already had the scripts for on and off within init.d (LEDsON and LEDsOFF) and both work so i used commands to call them in this toggle script, but what i cant get to work is a way to read the value of 'max_brightness', whether is is 0 or 15. i've used the -eq but i get '-eq' not found , or 0 not found, etc, ive used brakets and those dont get found either, anyone can help?

in reality i dont know what code to use to open max_brightness and for the script to read the number inside of it, and this is the most important part of the conditional script, w/o it the toggle wont work.

Not having an esteem I can't really tell you unless you send me a copy of the file that you're attempting to edit.
Once I see it's source I might be able to get something working for you.
Copy it to your sd card, put it on your comp, and copy the txt in it into a "
Code:
" box on the forums, maybe I'l be able to figure it out for you.
It SHOULDN'T be different, but apparently is.
 
Upvote 0
Not having an esteem I can't really tell you unless you send me a copy of the file that you're attempting to edit.
Once I see it's source I might be able to get something working for you.
Copy it to your sd card, put it on your comp, and copy the txt in it into a "
Code:
" box on the forums, maybe I'l be able to figure it out for you.
It SHOULDN'T be different, but apparently is.[/QUOTE]
 
i think im failing bad at explaining whats happening, im so sorry. lets walk through it

-inside /sys/class/leds/button-backlight/ there is a file called max_brightness, with a number inside (15) right? if this number is changed to 0 the soft key lights turn off right? right, we'll call that number VALUE in this explanation to make things easier

-we figured out 2 scripts to change that VALUE back and forth from 0 to 15 and viceversa right? but now were trying to make a toggle so we dont have to use 2 separate scripts right? right.

-in the toggle script how do i tell it to go open max_brightness and check the VALUE to then decide which script to run? Thats my problem, i dont know what command/lines/codes to use to tell in the script to go check max_brightness' VALUE before running any of the 2 scripts

what code checks inside files and looks for a number/VALUE? -e,$, cat? i dont know
 
Upvote 0
i think im failing bad at explaining whats happening, im so sorry. lets walk through it

-inside /sys/class/leds/button-backlight/ there is a file called max_brightness, with a number inside (15) right? if this number is changed to 0 the soft key lights turn off right? right, we'll call that number VALUE in this explanation to make things easier

-we figured out 2 scripts to change that VALUE back and forth from 0 to 15 and viceversa right? but now were trying to make a toggle so we dont have to use 2 separate scripts right? right.

-in the toggle script how do i tell it to go open max_brightness and check the VALUE to then decide which script to run? Thats my problem, i dont know what command/lines/codes to use to tell in the script to go check max_brightness' VALUE before running any of the 2 scripts

what code checks inside files and looks for a number/VALUE? -e,$, cat? i dont know


Mkay, I'll try to break this down as simple as I can for you (no offense, just trying to clear the confusion.)

In my code
Code:
#!/system/bin/sh
if [ -e /sys/class/leds/button-backlight/max_brightness ]; then
if [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]
then
echo 15 > sys/class/leds/button-backlight/max_brightness
else
echo 0 > sys/class/leds/button-backlight/max_brightness
fi
fi

We see the first line is
Code:
#!/system/bin/sh

This is how it is determined to be a bash shell script.

in the next lines you'll see
Code:
if [ -e /sys/class/leds/button-backlight/max_brightness ]; then
if [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]

The "
Code:
if [ -e /sys/class/leds/button-backlight/max_brightness ];
Line is stating " -e " (If file exists) "/sys/class/leds/button-backlight/max_brightness" (FILE)
";" (Close argument)

Code:
then
if  [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]

Means:
Then
if concatenate value = 0 within file max_brightness

Code:
echo 15 > sys/class/leds/button-backlight/max_brightness
Means: Relay 15 as input to file max_brightness

Code:
else
Means: If the Value currently IN the file "max_brightness" is not equivalent to the requested value of "0" then do the next operation...

Which is:

Code:
echo 0 > sys/class/leds/button-backlight/max_brightness
Means" Set the code to '0' since I determined that it was 15 due to 15, and - being the only values that I input, and the file did not have the cancatenate value of 0.

Code:
fi
fi
is just how Hash - Bourne is set up to close the arguments.

Hopefully that allows you to understand what's going on in that.

IF NOT>>>

The script loads file max_brightness from the path sys/class/leds/button-backlight
Then it looks for anything containing a value of 0 (if you were using multiple numbers like 15, and the page had something containing 150 this could cause errors; but this page doesn't, so we can use concatenate value if 0.)
So the script determines whether 0 is on that page, and if not it sets it to 0. however "else" if it IS, then it sets it to 15.
Then it closes the scripts argrument. Very simple coding, actually.
 
Upvote 0
Mkay, I'll try to break this down as simple as I can for you (no offense, just trying to clear the confusion.)

In my code
Code:
#!/system/bin/sh
if [ -e /sys/class/leds/button-backlight/max_brightness ]; then
if [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]
then
echo 15 > sys/class/leds/button-backlight/max_brightness
else
echo 0 > sys/class/leds/button-backlight/max_brightness
fi
fi

We see the first line is
Code:
#!/system/bin/sh

This is how it is determined to be a bash shell script.

in the next lines you'll see
Code:
if [ -e /sys/class/leds/button-backlight/max_brightness ]; then
if [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]

The "
Code:
if [ -e /sys/class/leds/button-backlight/max_brightness ];
Line is stating " -e " (If file exists) "/sys/class/leds/button-backlight/max_brightness" (FILE)
";" (Close argument)

Code:
then
if  [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]

Means:
Then
if concatenate value = 0 within file max_brightness

Code:
echo 15 > sys/class/leds/button-backlight/max_brightness
Means: Relay 15 as input to file max_brightness

Code:
else
Means: If the Value currently IN the file "max_brightness" is not equivalent to the requested value of "0" then do the next operation...

Which is:

Code:
echo 0 > sys/class/leds/button-backlight/max_brightness
Means" Set the code to '0' since I determined that it was 15 due to 15, and - being the only values that I input, and the file did not have the cancatenate value of 0.

Code:
fi
fi
is just how Hash - Bourne is set up to close the arguments.

Hopefully that allows you to understand what's going on in that.

IF NOT>>>

The script loads file max_brightness from the path sys/class/leds/button-backlight
Then it looks for anything containing a value of 0 (if you were using multiple numbers like 15, and the page had something containing 150 this could cause errors; but this page doesn't, so we can use concatenate value if 0.)
So the script determines whether 0 is on that page, and if not it sets it to 0. however "else" if it IS, then it sets it to 15.
Then it closes the scripts argrument. Very simple coding, actually.

thanks, now I understand what -e and cat mean. Now I have to figure out why SManager tells me it doesn't find the brackets or the -eq, etc
 
Upvote 0
With a space between [ and -e I get [: not found, w/o the space I get [-e no found

Idk what the deal is

Maybe there is another way. Like creating a new file called fileX, then if fileX exist, delete it, create fileY and change value in max_brightness to 15.
Else, deleted fileY, create fileX, then change the value to 0

What does the command look like for creating a file and deleting it ? Because we don't really need to check max_brightness for values, all we need to do is switch back and forth
 
Upvote 0
perhaps because you didn't include the lines to make it a bash script?

I'm not entirely sure, but I DO know that the way you code, and what you put in it is all dependent on what type of unix shell scripting you're using...
here, this will help you figure out what you need to do for bash
http://tille.garrels.be/training/bash/

I copied ur script exactly.
 
Upvote 0
Hmmm....the directory structure's the same on the esteem? and the max setting is compliable (bush-ism, I know) - It complies with 15...so I'm not honestly sure why it won't work...let me try something, I'm going to put it in a different format than this, and see if that'll work for you.

Gimme a bit as this is all very new to me as far as *nix is concerned.

gonna try something; just hold for a bit 'k'.
 
  • Like
Reactions: V SuperUser V
Upvote 0
I copied ur script exactly.

say, do me a favor.


Try this:
Code:
#!/system/bin/sh
set -x
if [ -e /sys/class/leds/button-backlight/max_brightness ]; then
if [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]
then
echo 15 > sys/class/leds/button-backlight/max_brightness
else
echo 0 > sys/class/leds/button-backlight/max_brightness
fi
fi
and let me know everything it outputs.
 
Upvote 0
Check amazon bro! Some good deals or bestbuy haha. Or the good old newegg

ehh, I've got several (close to 50 ) websites I use for electronics.
Put it like this, my computers have their own renters insurance policy because they're valued at over 25 grand JUST for the computers (not counting monitors, keyboard, mice, etc.)
I dont' play when it comes to my station :p
 
Upvote 0
I copied ur script exactly.

hey, I think I know what your problem is...
I just had a similar issue when I edited it on the phone.

Open the scipt via the 'edit" button in script manager.
When you're in the edit screen, check the whitespace spacing between the brackets. For some reason when I coded mine by hand on the phone not all the spacing went through, and it was giving me the same issues you're having. Went in, and verified (and changed a few) spaces, and VOILA, back up and running.
 
Upvote 0
say, do me a favor.


Try this:
Code:
#!/system/bin/sh
set -x
if [ -e /sys/class/leds/button-backlight/max_brightness ]; then
if [ `cat /sys/class/leds/button-backlight/max_brightness` -eq 0 ]
then
echo 15 > sys/class/leds/button-backlight/max_brightness
else
echo 0 > sys/class/leds/button-backlight/max_brightness
fi
fi
and let me know everything it outputs.

This is what I get

ae8dd522-2d90-63e1.jpg
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones