Playing sounds in AppleScript
December 3, 2007 at 4:40 PM by Dr. Drang
While working on these scripts, I was amazed that AppleScript didn’t have a builtin way of playing sound files. It has the beep
command, which will play whatever your alert sound is set to; and it has the say
command, which will speak to you using a voice that you can choose from within the script. But nothing where you can say “play this sound file right here.”
Fortunately, Microcosm Software has a free application called Play Sound that fills this gap. Play Sound offers up no user interface and doesn’t appear in the dock. It’s what’s called a “scriptable faceless background application.” It exists only to provide a AppleScript dictionary with the play
, pause
, resume
, and stop
commands. You can adjust the volume, the start and stop positions (in seconds from the beginning of the sound), and the number of repetitions. So you can do things like
tell application "Play Sound"
play "HD:System:Library:Sounds:Glass.aiff" repeat 1
end tell
to get an alert that’s different from your normal system alert—assuming “Glass” isn’t your normal system alert. This command should be taken literally. It will repeat the sound once, which is to say that it will play it twice.