Skip to content

Instantly share code, notes, and snippets.

@Frizlab
Last active September 7, 2017 12:42
Show Gist options
  • Save Frizlab/5562830 to your computer and use it in GitHub Desktop.
Save Frizlab/5562830 to your computer and use it in GitHub Desktop.
A small shell script that can be used on macOS to change the sound volume from the Terminal. Requires bc (should be built-in on macOS).
#!/bin/bash
if [ -z "$1" -o "$1" -lt 0 -o "$1" -gt 100 ]; then
echo "Usage: $0 new_volume" >/dev/stderr
echo " new_volume must be between 0 and 100" >/dev/stderr
exit 1
fi
new_volume="$(echo "($1 * 8) / 100" | bc)"
osascript -e "tell application \"System Events\" to set volume $new_volume"; # Max is 8, min is 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment