Coder Social home page Coder Social logo

brightness's People

Contributors

hackerb9 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

megacos

brightness's Issues

Suggestion: Add option to cycle through all brightness levels

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

Bash variable expansion doesn't work for me

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.