Last active
December 21, 2021 14:39
-
-
Save JesseTG/e4f09615b5e4141b210e0debc6aca6ad to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/sh | |
SOUNDS_DIR="${HOME}/sounds" | |
echo $SOUNDS_DIR | |
shopt -s nullglob | |
array=($SOUNDS_DIR/**/*.wav) | |
echo "${array[@]}" | |
shopt -u nullglob # Turn off nullglob to make sure it doesn't interfere with anything later | |
soundfile="${array[$RANDOM % ${#array[@]}]}" # Note double-quotes to avoid extra parsing of funny characters in filenames | |
case "$(uname)" in | |
(MINGW*) | |
soundfile="${soundfile/$HOME/$USERPROFILE}" | |
powershell -ExecutionPolicy RemoteSigned -Command "(New-Object Media.SoundPlayer \"$soundfile\").PlaySync();";; | |
(Darwin) afplay "$soundfile" ;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment