Skip to content

Instantly share code, notes, and snippets.

@JesseTG
Last active December 21, 2021 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesseTG/e4f09615b5e4141b210e0debc6aca6ad to your computer and use it in GitHub Desktop.
Save JesseTG/e4f09615b5e4141b210e0debc6aca6ad to your computer and use it in GitHub Desktop.
#!/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