SHARE
TWEET

Untitled

a guest Dec 27th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # ASUS T100TA screen brightness control script.
  4. #
  5. # This script invokes xrandr to increase or decrease the brightness of
  6. # the screen by applying a software only modification that therefore
  7. # doesn't affect the power consumption. See the xrandr manual for more
  8. # info. This script also uses bc for floating point calculations.
  9. # Please note that Redshift (and possibly other similar applications),
  10. # if it is running, resets the brightness value every time and it
  11. # needs to be disabled.
  12.  
  13. # Copyright 2017 Francesco De Vita <devfra[at]inventati[dot]org>
  14. #
  15. # Licensed under the Apache License, Version 2.0 (the "License");
  16. # you may not use this file except in compliance with the License.
  17. # You may obtain a copy of the License at
  18. #
  19. #     http://www.apache.org/licenses/LICENSE-2.0
  20. #
  21. # Unless required by applicable law or agreed to in writing, software
  22. # distributed under the License is distributed on an "AS IS" BASIS,
  23. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  24. # implied.  See the License for the specific language governing
  25. # permissions and limitations under the License.
  26.  
  27.  
  28. # Min and max screen brigthness, correct values are between 0 and 1.
  29. min_brightness=0.2
  30. max_brightness=1
  31.  
  32.  
  33. # Display usage if wrong input arguments are supplied.
  34. if [[ $# -ne 1 ]] || [[ $1 != "decrease" && $1 != "increase" ]]
  35. then
  36.     echo "ASUS T100TA screen brightness control script"
  37.     echo "Usage: $0 [decrease|increase]"
  38.     exit 1
  39. fi
  40.  
  41.  
  42. # Check if xrandr and bc are installed.
  43. hash xrandr 2>/dev/null || { echo "xrandr is not installed"; exit 1; }
  44. hash bc 2>/dev/null || { echo "bc is not installed"; exit 1; }
  45.  
  46.  
  47. # Xrandr output for the screen, supposing no external screen attached.
  48. screen_output=$(xrandr | grep -w connected | cut -d" " -f1)
  49.  
  50. # Current brightness.
  51. brightness=$(xrandr --current --verbose | grep Bright | cut -d" " -f2)
  52.  
  53.  
  54. # Decrease or increase the screen brightness.
  55. case $1 in
  56.     decrease)
  57.         if [[ $(echo "$brightness>$min_brightness" | bc) -eq 1 ]]
  58.         then
  59.             brightness=$(echo "$brightness-0.2" | bc)
  60.             xrandr --output $screen_output --brightness $brightness
  61.         fi
  62.         ;;
  63.     increase)
  64.         if [[ $(echo "$brightness<$max_brightness" | bc) -eq 1 ]]
  65.         then
  66.             brightness=$(echo "$brightness+0.2" | bc)
  67.             xrandr --output $screen_output --brightness $brightness
  68.         fi
  69.         ;;
  70. esac
  71.  
  72. exit 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top