#!/bin/bash # Name and description name="mixer-osd" description="Provides an OSD (On Screen Display) for basic mixer operations." # Some variables default_color="green" acolor=$default_color # This program depends on aosd_cat and amixer (alsa-utils in Debian) deps="aosd_cat amixer" function usage() { show_name=$1 error=$2 # Show name and description only if explicitly stated if [[ $show_name == 1 ]] ; then echo -e " $name - $description\n" fi # Show an error message, if present if [[ $error != '' ]] ; then echo -e "\033[1m$error\033[0m\n" fi cat << EOF Usage: $name -u|-d|-m $name -h Options: -u Volume up -d Volume down -m Mute/Unmute -h Shows this help. EOF } # Check for dependencies for dep in $deps ; do if [[ `which $dep` == '' ]] ; then echo "Please, install $dep for $name to work!" exit 1 fi done # Managing options while getopts "hudm" option ; do case $option in h ) usage 1 exit 0 ;; u ) aarg="Volume ↑ $(amixer -c 0 sset Master 2+ unmute | tail -1 | awk '{print $4}' | tr -d '[]')" acolor="royalblue" ;; d ) aarg="Volume ↓ $(amixer -c 0 sset Master 2- unmute | tail -1 | awk '{print $4}' | tr -d '[]')" acolor="gray50" ;; m ) case $(amixer -c 0 sset Master toggle | tail -1 | awk '{print $6}' | tr -d '[]') in on ) aarg="UNMUTED" acolor="green" ;; off ) aarg="MUTED" acolor="red" ;; esac ;; \? ) echo -e "Please type ${name} -h for help on usage." exit 1 ;; esac done shift $(($OPTIND - 1)) # This program doesn't accept any other argument than flag-options if [[ $# -gt 0 ]] ; then usage 0 "Invalid argument (\`$1')." exit 1 fi # One have to either mute/unmute or change the volume, # otherwise program will exit with error code 1 if [[ -z $aarg ]] ; then usage 0 "Please, mute/unmute or change the volume!" exit 1 fi # Kills any instance of aosd_cat pkill aosd_cat >/dev/null 2>&1 # Performs osd-ized volume changes echo "$aarg" | aosd_cat \ --fore-color=$acolor \ --position 4 \ --font="Droid Sans Bold 32" \ --y-offset=300 \ --transparency=2 \ --back-color="gray10" \ --back-opacity=50 \ --padding=20 \ --fade-full=1500 >/dev/null 2>&1 & exit $?