Adjusting a Mac's System Volume on the Command Line

https://lobste.rs/rss Hits: 4
Summary

Adjusting a Mac's System Volume on the Command Line Posted on February 10, 2022 · 611ish words · 2 minute read Because I’m approximately 270 years old and listen to music (MP3 files, no less!) on my computer instead of a smart speaker, sometimes I find myself wanting to adjust my Mac’s system volume without needing to, say, get up from the couch. I’m sure there’s plenty of iOS apps that can do that with varying amounts of tracking and in-app-purchases, but because, once again, I’m practically 270 years old, I prefer to SSH into my computer and run a command. Thanks to AppleScript, the amount of trickery required to make this possible is kept to a minimum: Keeping in mind that the built-in osascript utility executes AppleScript code, running… osascript -e "set volume output volume 100" …will turn the volume up to its maximum – the number is interpreted as a percentage. You can also make things louder or quieter by some percentage points… osascript -e "set volume output volume (output volume of (get volume settings) - 42)" …or (un)mute the computer: osascript -e "set volume with output muted" osascript -e "set volume without output muted" But, as you can see, these commands are a bit unintuitive and a lot unwieldy. To provide a better user experience in the “lazy couch potato” use case, I’ve written a few lines of bash that provide fewer-keystrokes access to these volume controls: #!/bin/bash USAGE="usage: vol [-h | --help | NUMBER_FROM_0_TO_100 | -DECREMENT | +INCREMENT]" # if the argument isn't one of the expected values, display usage instructions if [ "$1" == "-h" ] || [ "$1" == "--help" ] || ! [[ "$1" =~ ^$|^[+-]?[0-9]+$ ]]; then echo "$USAGE" exit 1 fi # retrieve old volume OLD_VOLUME="$(osascript -e "output volume of (get volume settings)")" if [ -z "$1" ]; then echo "$OLD_VOLUME %" else # default case: just set volume to specified value NEW_VOLUME="$1" # alternatively: decrement or increment? if [[ "$1" == -* ]] || [[ "$1" == +* ]]; then NEW_VOLUME=$(($OLD_VOL...

First seen: 2026-05-23 05:29

Last seen: 2026-05-23 14:37