Advertisement
Gotolei

redshiftbrightness.sh

Sep 17th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. input="$1"
  4. #either 1 or -1, must be int
  5.  
  6. #turn off redshift animations if you don't want to commit die
  7.  
  8. pid=$(pidof redshift)
  9.  
  10. if [[ $pid -eq 0 ]]
  11. then
  12.   number=10
  13. else
  14.   current=$(ps --no-headers $pid | awk '{print $7}')
  15.   number="${current//.}"
  16. fi
  17.  
  18. new=$((number + input))
  19.  
  20. if (( $new > 10 ))
  21. then
  22.   #echo "Redshift: Max brightness reached"
  23.   new=10
  24. fi
  25.  
  26. if (( $new < 1 ))
  27. then
  28.   #echo "Redshift: Min brightness reached"
  29.   new=1
  30. fi
  31.  
  32. displayval=$((new * 10))
  33.  
  34. newnum=$(echo "scale=1; $new/10" | bc)
  35. #convert 10 to 1.0 etc
  36.  
  37. killall redshift
  38. redshift -b "${newnum}" &
  39.  
  40. if [ ! -s /dev/shm/rsnotifid ]
  41. then
  42.   #echo "Redshift brightness: creating temp file"
  43.   touch /dev/shm/rsnotifid
  44.   echo 0 > /dev/shm/rsnotifid
  45. fi
  46.  
  47. replaceid=$(cat /dev/shm/rsnotifid)
  48.  
  49. replaceidnew=$(gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify redshiftbrightness.sh ${replaceid} redshift "" "" [] "{'String':<0>,'value':<${displayval}>,'String':<0>,'transient':<'true'>}" 2000 | cut -c 9- | egrep -o '[0-9]+')
  50.  
  51. echo $replaceidnew > /dev/shm/rsnotifid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement