URI:
       volume - scripts - various script and utils
  HTML git clone git://z3bra.org/scripts
   DIR Log
   DIR Files
   DIR Refs
       ---
       volume (887B)
       ---
            1 #!/bin/sh
            2 
            3 export LC_ALL=C
            4 
            5 usage() {
            6         echo "usage: $(basename $0) [-c sink/source] [volume%|toggle]" >&2
            7 }
            8 
            9 muted() {
           10         pactl get-${control}-mute $1|cut -d' ' -f2
           11 }
           12 
           13 getvolume() {
           14         pactl get-${control}-volume $1|grep -Eo "[0-9]+%"|uniq
           15 }
           16 
           17 setvolume() {
           18         pactl set-${control}-volume $1 $2
           19 }
           20 
           21 togglevolume() {
           22         pactl set-${control}-mute $1 toggle
           23 }
           24 
           25 # default to output management
           26 control=sink
           27 
           28 while getopts "hc:" OPT; do
           29         case $OPT in
           30         c) control="$OPTARG";;
           31         h) usage; exit 0;;
           32         *) usage; exit 1;;
           33         esac
           34 done
           35 
           36 shift $((OPTIND - 1))
           37 
           38 case $(basename $0) in
           39 speakers)   control=sink ;;
           40 microphone) control=source ;;
           41 esac
           42 
           43 # get default controlled device
           44 target=$(pactl get-default-${control})
           45 
           46 if [ "$#" -eq 0 ]; then
           47         case $(muted $target) in
           48         yes) echo off ;;
           49         no) getvolume $target ;;
           50         esac
           51         exit
           52 fi
           53 
           54 case $1 in
           55 toggle|-) togglevolume $target ;;
           56 *)        setvolume $target $1 ;;
           57 esac