How can I play a sound from the command line in Mac OS X?
Matthew Harrington
I would like to play a short sound file from the command line in Mac OS X, independent of any audio player application, in order to provide notification that a long job has finished.
3 Answers
There is a built-in tool: afplay <sound file>. The man page does not document all of its options, which can be found via afplay -h:
Usage:
afplay [option...] audio_file
Options: (may appear before or after arguments) {-v | --volume} VOLUME set the volume for playback of the file {-h | --help} print help { --leaks} run leaks analysis {-t | --time} TIME play for TIME seconds {-r | --rate} RATE play at playback rate {-q | --rQuality} QUALITY set the quality used for rate-scaled playback (default is 0 - low quality, 1 - high quality) {-d | --debug} debug print outputIt will not play more than one audio file.
2One time, when the power went off at work, knowing that my firewall would return to that last state (powered on) when the electricty came back on, I wrote a script in bash that used the say command to wake me up when the power came back on.
Have you considered printf "\a\a\a" or echo -e "\a\a\a"?