#!/bin/sh help() { cat << EOF $0: Wrapper script to change volume options: -i [Vol] Increase volume by Vol -d [Vol] Decrease volume by Vol -s [Vol] Set volume to Vol -p Show the current volume -t Toggle between mute and unmute -h Print this message and exit EOF } err() { echo "$*" >&2 exit 1 } run() { if ! ${1} > /dev/null 2>&1; then err "${2}" fi } if ! command -v pactl > /dev/null 2>&1; then err "${0}: pulseaudio must be installed" fi if [ $# != 1 ] && [ $# != 2 ]; then err "${0}: Invalid usage Try '$0 -h' for help." fi while getopts "i:d:s:pth" option; do case "${option}" in i) run "pactl set-sink-volume @DEFAULT_SINK@ +${OPTARG}%" \ "${0}: Failed to increase volume" exit 0 ;; d) run "pactl set-sink-volume @DEFAULT_SINK@ -${OPTARG}%" \ "${0}: Failed to decrease volume" exit 0 ;; s) run "pactl set-sink-volume @DEFAULT_SINK@ ${OPTARG}%" \ "${0}: Failed to set volume" exit 0 ;; t) run "set-sink-volume @DEFAULT_SINK@ toggle" \ "${0}: Failed to toggle volume" exit 0 ;; p) if ! pactl get-sink-volume @DEFAULT_SINK@ 2>/dev/null; then err "Failed to get current volume" else exit 0 fi ;; h) help; exit 0 ;; *) err "Try '${0} -h' for help" ;; esac done err "${0}: Invalid usage Try '$0 -h' for help."