How to play alert other than BEEP?

Simple question, couldn’t find answer via search…

How do I play one of the system sound effects, like ping or hero or frog or …?

Is it like the “BEEP” comand or something more complex?

chico

Hi,

I don’t know of any freeware scripting addition or app that plays OSX sounds directly. However there are two I know of that plays sound files:

http://www.seanet.com/~jonpugh/

and

http://microcosmsoftware.com/playsound/

Jon’s Commands plays pre-OSX System Sounds. You may not want to use this becuse you need to convert the OSX aiff sounds to pre-OSX snd file. This might be good if you’re using sounds from OS9 and below.

Play Sound is an easy to use and versatile sound player. It is not a scripting addition, but plays sounds in the background.

What you need to do is duplicate one of the aiff sounds from:

“Macintosh HD:System:Library:Sounds:”

I think it’s located in the same place in Panther (I use Jaguar).

After you install Play Sound, you can easily play your sound from the background with

tell app “Play Sound”
play (reference_to_your_aiff)
end tell

gl,

Thanks. If it were really important for me to play a particular sound, I’d use one of your suggestions.

I just wondered how to to replace the annoying “beep” with one of the more pleasing beep-type sounds as an alert. I had hoped there was a simple command to do so.

I can live with the beep…but it sounds so Old School, so OS 9…

Hi chico,

Sorry, I didn’t know you wanted to change the beep. You can’t because it’s a scripting addition. Play Sound works well though and quickly and it’s kind of simple. It’s a good app to download. You can place it in the dock and drop sounds on it also.

gl,

Thanks, I’ll add that to my bag of tricks.

Instead of using BEEP, I changed my code to SAY “(something)”. Turns out that some of the voices can be used to mumble a syllable or speak a word or two that sound far better than the BEEP, so that’s my cheap fix.

Here’s the way to intercept the beep with a command handler and no continue:

beep 3
display dialog “It worked!”

on beep n
set sys_lib to (path to “dlib” from System domain)
set basso_ref to (“” & sys_lib & “Sounds:Basso.aiff”) as alias
tell application “Play Sound”
play basso_ref repeat n
end tell
return
end beep

gl,

Wait, you need to use (n-1) as the repeat number:

beep 3
display dialog “It worked!”

on beep n
set sys_lib to (path to “dlib” from System domain)
set ssnd_ref to (“” & sys_lib & “Sounds:Ping.aiff”) as alias
tell application “Play Sound”
play ssnd_ref repeat (n - 1)
end tell
return
end beep

gl,

thanks for the tip, kel. unfortunately for some reason your method did not work for me. i might have had a conflict between an older version of play sound and jon’s commands. but i got play sound to work, and here’s my method, which i think is pretty nice.

set result to dosound(4) of me


on dosound(x)
	tell application "Finder"
		set thefiles to every file of folder "Sounds" of folder "Library" of folder "system" of startup disk whose kind contains "aiff"
		if x ≤ (count thefiles) then
			set thefile to (item x of thefiles) as alias
			tell application "Play Sound"
				«event µSNDplay» thefile
			end tell
		end if
	end tell
	return thefile
	(* 
--using play sound
-- http://microcosmsoftware.com/playsound/
on my system:

Basso.aiff
Blow.aiff
Bottle.aiff
Frog.aiff
Funk.aiff
Glass.aiff
Hero.aiff
Morse.aiff
Ping.aiff
Pop.aiff
Purr.aiff
Sosumi.aiff
Submarine.aiff
Tink.aiff
*)
end dosound

Or you can make it an Xcode app, and drag it to the sounds tab in the MainMenu.nib

of which you would use:

set theSound to load sound "thesound"
play theSound

You could always change it using System Preferences/Sound…

Alternatively:

to playSoundNumber(n)
	set f to path to "ssnd" as Unicode text
	tell application "Play Sound" to try
		play f & (list folder f)'s item n as alias
	end try
end playSoundNumber

playSoundNumber(4)

Or, specifying a sound file by name:

to playSound(s)
	tell application "Play Sound" to play (path to "ssnd" as Unicode text) & s as alias
end playSound

playSound("Frog.aiff")

I often use the CLI utility ‘afplay’, built into OS X. Audio File Player takes the path to a QuickTime supported audio file (mp3, caf, aif, aiff etc), and plays the sound. For more info on afplay, look up it’s manual page in Terminal (“man afplay”)

This is the routine I usually use for audio playback:


on SoundPlay(t, f)

	repeat t times
		try
			do shell script "afplay \"" & f & "\""
		on error
			log "Sound File not found, skipping playback!"
			exit repeat
		end try
	end repeat
end SoundPlay

This is an example usage of the routine playing back the Basso.aiff file in the System folder 3 times:


SoundPlay(3, "/System/Library/Sounds/Basso.aiff")

Hope I’ve helped :slight_smile:

Model: iMac 27" (Late 2013)
AppleScript: 2.3.2
Browser: Safari 537.78.2
Operating System: Mac OS X (10.8)

Hi tjone270,

You’re replying to posts from 2005. Things are much different now.

gl,
kel

Hi tjone270,

Although, your post is interesting. I can’t remember reading about afplay in unix.

I think I posted not too long ago about adding a sound player to your Script Libraries. If you do that, you can also add effects. For instance, say you wanted the sound to echo. That sounds pretty good. If you’re interested, I can post the library script tomorrow.

gl,
kel

It’s a command line utility that ships with Mac OS X since Leopard.

Hi tjone270.

Welcome to MacScripter and thanks for the suggestion. One of the nice things about ‘afplay’ is that it comes with the system and doesn’t require any third-party software.

Looking back through this thread, I see that in 2005, kel demonstrated intercepting ‘beep’ with one’s own code. I’ve been fooling with this this morning using a call to your handler. It seems possible to work it even when no number’s provided with the command:


on SoundPlay(t, f)
	
	repeat t times
		try
			do shell script "afplay \"" & f & "\""
		on error
			log "Sound File not found, skipping playback!"
			exit repeat
		end try
	end repeat
end SoundPlay

on beep n
	if (n's class is not integer) then set n to 1
	SoundPlay(n, "/System/Library/Sounds/Basso.aiff")
end beep

beep

Another variation ” irrelevant here, but interesting ” is to let the default beep sound when there’s no number:


on beep n
	if (n's class is integer) then
		SoundPlay(n, "/System/Library/Sounds/Basso.aiff")
	else
		continue beep
	end if
end beep

Or by appending a number to the ‘continue beep’, one can make the default number of beeps something other than 1. :slight_smile:

Ah. Sunday mornings. :wink:

Sunday evenings are also nice!

I see no problems in adding the path in front of afplay, since it is preinstalled, and very unlikely to move, once it is there. (Leopard and later ). This will speed up execution, just a tiny bit, but still.

on SoundPlay(t, f)
	
	repeat t times
		try
			do shell script "/usr/bin/afplay \"" & f & "\""
		on error
			log "Sound File not found, skipping playback!"
			exit repeat
		end try
	end repeat
end SoundPlay