scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

volume (1069B)


      1 #!/bin/sh
      2 
      3 #OpenBSD volume control
      4 #normalizes the input percentage to 0-255
      5 #since openbsd 6.7 it attempts to use 
      6 #the correct interface (mixerctl/sndioctl)
      7 
      8 printvolmixctl() {
      9         currval=$(mixerctl|grep outputs.master\=|awk -F"," '{print $NF}')
     10         currval=$(echo $currval "/ 2.55"|bc)
     11         echo "Current level:" $currval "%"
     12 }
     13 
     14 printvolsndctl() {
     15         currval=$(sndioctl|grep output.level\=|awk -F"=" '{print $NF * 100}'|sed 's/\..*//')
     16         echo "Current level:" $currval "%"
     17 }
     18 
     19 usageexit() {
     20 	typeset -i currval
     21 	echo "usage:" "$(basename $0) [0-100]"
     22 	if [ $vers -gt 67 ]; then
     23 		printvolsndctl
     24 	else
     25 		printvolmixctl
     26 	fi
     27 	exit
     28 }
     29 
     30 vers=$(uname -r|tr -d ".")
     31 case $1 in
     32 	+([0-9]) )
     33 		if [  $1 -gt 100 -o $1 -lt 0 ]; then
     34 			usageexit
     35 		fi
     36 		if [ $vers -gt 67 ]; then
     37 			volvar=$(echo $1|awk '{ print $1 / 100 }')
     38 			sndioctl output.level=$volvar
     39 			printvolsndctl
     40 		else
     41 			typeset -i volvar
     42 			volvar=$(printf "%1.0f" $(echo  $1 "* 2.55" |bc))
     43 			mixerctl -n outputs.master=$volvar,$volvar
     44 			printvolmixctl
     45 		fi
     46 		;;
     47 	*)
     48 		usageexit
     49 		;;
     50 esac