Skip to content

Instantly share code, notes, and snippets.

@geolaw
Last active January 20, 2023 17:24
Show Gist options
  • Save geolaw/246322b626b0b2b29d46dfa8f8e3e2c1 to your computer and use it in GitHub Desktop.
Save geolaw/246322b626b0b2b29d46dfa8f8e3e2c1 to your computer and use it in GitHub Desktop.
macos volume adjustment with skhd
more from my linux i3wm -> macos conversion.
very used to being able to adjust my volume up and down or muted with a keystroke.
Note - using a standard generic keyboard, not an Apple keyboard, no special multimedia keys
2 bash scripts - could possibly combine them into one, but later ...
First to change the volume up and down.
~ cat bin/change_volume
#!/bin/bash
if [ "$2" != "" ]; then
count=$2
else
count=5
fi
current_vol=$(osascript -e 'output volume of (get volume settings)')
if [ "$1" == "up" ]; then
((current_vol=current_vol+$count))
else
((current_vol=current_vol-$count))
fi
osascript -e "set volume output volume $current_vol"
second - just checks to see if we're currently muted / unmuted and toggles the other way
~ cat bin/mute_unmute
#!/bin/bash
current=$(osascript -e "output muted of (get volume settings)")
if [ "$current" == "true" ]; then
osascript -e "set volume without output muted"
else
osascript -e "set volume with output muted"
fi
----------------------------------------------
skhd keybindings :
alt - left: ~glaw/bin/change_volume down 1
alt - right: ~glaw/bin/change_volume up 1
alt - down: ~glaw/bin/change_volume down 5
alt - up: ~glaw/bin/change_volume up 5
alt - m : ~glaw/bin/mute_unmute
-----------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment