Advertisement
Gotolei

redshiftbrightness.sh

Aug 25th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. input="$1"
  4. #either 1 or -1, must be int
  5.  
  6. current=$(ps -ef | grep 'redshift \-b' | tail -c 4)
  7. number="${current//.}"
  8. #convert 1.0 to 10 etc
  9.  
  10.  
  11. new=$((number + input))
  12.  
  13. if (( $new > 10 ))
  14. then
  15.   echo "Redshift: Max brightness reached"
  16.   new=10
  17. fi
  18.  
  19. if (( $new < 1 ))
  20. then
  21.   echo "Redshift: Min brightness reached"
  22.   new=1
  23. fi
  24.  
  25.  
  26. displayval=$((new * 10))
  27.  
  28. newnum=$(echo "scale=1; $new/10" | bc)
  29. #convert 10 to 1.0 etc
  30.  
  31.  
  32. killall redshift
  33. redshift -b "${newnum}" &
  34.  
  35.  
  36. if [ ! -e /tmp/rsnotifid ]
  37. then
  38.   echo "Redshift brightness: creating temp file"
  39.   touch /tmp/rsnotifid
  40.   echo 0 > /tmp/rsnotifid
  41. fi
  42.  
  43. replaceid=$(cat /tmp/rsnotifid)
  44.  
  45. replaceidnew=$(gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify appname ${replaceid} display-brightness-symbolic "" "" [] "{'String':<0>,'value':<${displayval}>}" 2000 | cut -c 9- | egrep -o '[0-9]+')
  46. #regex="([0-9]+),"
  47. #replaceidnew=$(gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify appname ${replaceid} display-brightness-symbolic "" "" [] "{'String':<0>,'value':<${displayval}>}" 2000 | egrep -o $regex)
  48.  
  49. echo $replaceidnew > /tmp/rsnotifid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement