Skip to content

Instantly share code, notes, and snippets.

@noahcoad
Created April 28, 2021 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahcoad/b36d9bce7c498ff5cc1ad19fa15a742d to your computer and use it in GitHub Desktop.
Save noahcoad/b36d9bce7c498ff5cc1ad19fa15a742d to your computer and use it in GitHub Desktop.
#!/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