Last active
November 7, 2023 18:26
-
-
Save dnedrow/01dd349ce520eadf3f979aebe5c9a064 to your computer and use it in GitHub Desktop.
Returns a percentage value for use with scripts that play sounds on the Mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env zsh | |
| # Usage: | |
| # Source this and then use the function with afplay | |
| # afplay -v $( getsuggestedvolume ) foo.wav | |
| function getsuggestedvolume() { | |
| (( systemVolume=$(osascript -e 'output volume of (get volume settings)') )) | |
| (( currentVolume=`echo "scale=2; $systemVolume/100" | bc -l` )) | |
| (( normalizedVolume=`echo "scale=2; $currentVolume/3" | bc -l` )) | |
| (( maxVolume=0.33 )) | |
| printf "%.2f" $(( $normalizedVolume<=$maxVolume?$normalizedVolume:$maxVolume )) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment