Skip to content

Instantly share code, notes, and snippets.

@noahcoad
Created Apr 28, 2021
Embed
What would you like to do?
#!/bin/bash
# 2021-04-28 by Noah Coad
# simple bash script to turn the Mac OSX volume up, down, get value, or set
# vol = get current volume level
# vol u = volume up by 5%
# vol d = volume down by 5%
# vol 25 = set volume level between 0-100
re='^[0-9]+$'
dir=
if [[ "$1" == "u" ]]; then # volume up
dir=+
elif [[ "$1" == "d" ]]; then # volume down
dir=-
elif [[ "$1" == "" ]]; then
echo $(osascript -e 'output volume of (get volume settings)')
elif [[ $1 =~ $re ]]; then
osascript -e "set volume output volume $1"
else
echo Control OSX Volume Level: vol '[u/d/#]'
fi
# volume up or down
if ! [[ -z "$dir" ]]; then
osascript -e "set volume output volume $(( ( $(osascript -e 'output volume of (get volume settings)') $dir 5 ) / 5 * 5))"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment