Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How can I play a sound from the command line in Mac OS X?

Writer 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 output

It will not play more than one audio file.

2

One 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.

3

Have you considered printf "\a\a\a" or echo -e "\a\a\a"?

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy