hackerb9 / brightness Goto Github PK
View Code? Open in Web Editor NEWIncrease/decrease brightness, to be bound to key shortcuts
License: GNU General Public License v3.0
Increase/decrease brightness, to be bound to key shortcuts
License: GNU General Public License v3.0
Would it be possible to add an option to loop through each brightness level in increments of 10 up to 100 and then reset back to 0 and start again. For example if you specified the argument: "cycle" to the brightness command it would simply add the increment of 10 or a defined variable to the total brightness up to the max value (100) and then loop back to 0 when called again.
For example, I modified the code by adding a third argument "cycle", you could also add a cycle value variable instead of hard coding 10 if you did not want to increment by 10 each time:
b=$(xrandr --current --verbose | grep Brightness) # Get current brightness
b=${b##*: } # Remove "Brightness: "
b=${b#0.} # Remove decimal point, e.g. 0.30 --> 30
level=10 # Brightness level increments
[[ $b == "1.0" ]] && b="100" # if b = 1.0 then b = 100
case $1 in
+*|-*)
b=$((b $1)) # b=b+n, b=b-n
;;
[0-9]*)
b=$1 # b=n
;;
cycle)
b=$((b + $level)) # b=b+level
;;
*)
echo $b; exit
;;
esac
[[ $b -lt 0 ]] && b=0 # if b < 0 then b = 0
if [[ $b -gt 100 ]]; then
b=0
fi
if [[ $b -eq 100 ]]; then
b=1.0
else
b=0.$b
fi
outputs=$(xrandr --current | awk '$2 == "connected" {print $1}')
for o in $outputs; do
xrandr --output $o --brightness $b
done
The tool doesn't work for me.
$ brightness +10
/usr/local/bin/brightness: line 19: 81
Brightness: 0.81
Brightness: 0.81: syntax error in expression (error token is "Brightness: 0.81
Brightness: 0.81")
/usr/local/bin/brightness: line 21: [[: 81
Brightness: 0.81
Brightness: 0.81: syntax error in expression (error token is "Brightness: 0.81
Brightness: 0.81")
/usr/local/bin/brightness: line 22: [[: 81
Brightness: 0.81
Brightness: 0.81: syntax error in expression (error token is "Brightness: 0.81
Brightness: 0.81")
/usr/local/bin/brightness: line 24: [[: 81
Brightness: 0.81
Brightness: 0.81: syntax error in expression (error token is "Brightness: 0.81
Brightness: 0.81")
xrandr: unrecognized option 'Brightness:'
Try 'xrandr --help' for more information.
xrandr: unrecognized option 'Brightness:'
Try 'xrandr --help' for more information.
xrandr: unrecognized option 'Brightness:'
Try 'xrandr --help' for more information.
On closer inspection, this is where the script falls through for me. Why doesn't the transformation not work for multiple lines?
$ b=$(xrandr --current --verbose | grep Brightness) && echo "$b"
Brightness: 0.81
Brightness: 0.81
Brightness: 0.81
$ echo "${b#*: }"
0.81
Brightness: 0.81
Brightness: 0.81
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.