How do I make this script less brainlet? Need it for lowering brightness on the TV, which obviously doesn't have any actual ACPI power brightness controls like laptops.
1 if grep -o "1.0" ~/Downloads/shell/bright ; then
2 xrandr --output HDMI-2 --brightness 0.9 && echo "0.9" > ~/Downloads/shell/bright
3
4 elif grep -o "0.9" ~/Downloads/shell/bright; then
5 xrandr --output HDMI-2 --brightness 0.8 && echo "0.8" > ~/Downloads/shell/bright
6
7 elif grep -o "0.8" ~/Downloads/shell/bright; then
8 xrandr --output HDMI-2 --brightness 0.7 && echo "0.7" > ~/Downloads/shell/bright
9
10 elif grep -o "0.7" ~/Downloads/shell/bright; then
11 xrandr --output HDMI-2 --brightness 0.6 && echo "0.6" > ~/Downloads/shell/bright
12
13 elif grep -o "0.6" ~/Downloads/shell/bright; then
14 xrandr --output HDMI-2 --brightness 0.5 && echo "0.5" > ~/Downloads/shell/bright
15
16 elif grep -o "0.5" ~/Downloads/shell/bright; then
17 xrandr --output HDMI-2 --brightness 0.4 && echo "0.4" > ~/Downloads/shell/bright
How do I make this script less brainlet? Need it for lowering brightness on the TV...
Use python
No.
>elif grep
>elif grep
>elif grep
>elif grep
>elif grep
Then have fun with your elif's and pajeet tier code
Don't care, I'm no programmer, but I have use for a script like this.
Bash can be kind of squirrely. Might want to move the parsing and conditional part to a C program. Have that output a command line which bash can then execute.
Alright man
Can you not do math in this? Seems like you have an n - 0.1 relationship which you can use in one block of code.
if input = n:
output to hdmi (n - 0.1)
I can believe people can bash in this very board
just use a switch case, OP, or the value of the file as an argument
let nigger = value-1
xrander .... nigger
Whats in the bright file, just a number between 0 and 1.0?
1.0 to 0.4
It works, this is just for a remote control, I got a different script that sets the brightness back to 1.0 when I want it back.
bc
try this perl script
#!/usr/bin/perl
use strict;
use warnings;
use v5.010;
my $file = "~/Downloads/shell/bright";
my $value = qx % cat "$file" | tr -d '\n' %;
unless ($value = 1) {
$value -= 0.1;
qx % echo "$value" > "$file" %;
qx % xrandr --output HDMI-2 --brightness $value %;
}
t. Luke
Thanks, but I can't literally read this shit.
At least my pajeet one is readable to myself
parse the value inside of ~/Downloads/shell/bright
subtract 0.1
handle the case where it's already 0
shove the value back into the file
So read it over until you understand. It does the same thing your code does in far less lines.
I removed a bug I found that occurs when brightness is set back to 1. I have also annotated the code so that you can understand what is going on.
btw "qx % %" evals what is between the % % like $( ) or `` in bash (and maybe other shells too)
save this file and run it if you have perl installed
#!/usr/bin/perl
use strict;
use warnings;
use v5.010;
# the path to your bright file
my $file = "~/Downloads/shell/bright";
# read file with `cat' and use `tr' to remove newline character
my $value = qx % cat "$file" | tr -d '\n' %;
# if brightness level is NOT (less than or equal to 0.4)
unless ($value "$file" %;
# call xrandr with the newly decreased brightness value
qx % xrandr --output HDMI-2 --brightness $value %;
}
This works well, thank you for explaining me what the fuck the perl syntax means.
Perl and ruby fags are hilarious
Bash all the way, my lads