juliuszint / asdbctl

Small command line utility to get/set the brightness of Apple Studio Displays from Linux
MIT License
28 stars 3 forks source link

Bash script to increase or decrease brightness #5

Open kooskaspers opened 3 weeks ago

kooskaspers commented 3 weeks ago

I wrote a small script to increase or decrease the brightness with a single command. This is handy in case one would increase or decrease the brightness by making use of a keypress bind.

#!/bin/sh
#
#afronden op hele getallen
brightness=$(printf "%.0f\n" $(sudo asdbctl get | awk '{print $5}'  | awk '{ print $1/600 }'))
echo "current brightness is" $brightness
if [[ $1 == "up" ]]; then
  case 1 in
      $(($brightness <= 8)))((brightness+=2)); sudo asdbctl set $brightness; echo "1";;
      $(($brightness > 8 && $brightness < 20)))brightness=20; sudo asdbctl set $brightness; echo "2";;
      $(($brightness >= 20 && $brightness < 80)))((brightness+=20)); sudo asdbctl set $brightness; echo "3";;
      $(($brightness >= 80)))brightness=100; sudo asdbctl set $brightness; echo "3";;
      *)echo "error";;
  esac
elif [[ $1 == "down" ]]; then
  case 1 in
      $(($brightness > 20 )))((brightness-=20)); sudo asdbctl set $brightness;;
      $(($brightness > 10 && $brightness <= 20)))brightness=10; sudo asdbctl set $brightness;;
      $(($brightness > 2  && $brightness <=10  )))((brightness-=2)); sudo asdbctl set $brightness;;
      $(($brightness <= 2 )))brightness=0; sudo asdbctl set $brightness;;
      *)echo "error";;
  esac
else
    echo "no valid input given (up / down). halt."
    exit 1
fi  
dunstify --appname=asdbctl -r 345678 "Set brightness to $brightness"
echo "setting to" $brightness

Usage: To increase brightness: ./script.sh up

To decease brightness: ./script.sh down

juliuszint commented 2 weeks ago

Would certainly make sense to embed something like this into asdbctl . This will probably happen once I am ready to merge #6