A handler to play with the system sounds

Hello.

This is just a small hander which creates a list of the system sounds, should you wish to hear what different combinations of them sounds like, or just find the one which suits your scripts well.


set mySounds to makeSoundsTable()
set soundCount to count mySounds

repeat with i from 1 to soundCount
	do shell script "(/usr/bin/afplay " & item i of mySounds & "; /usr/bin/afplay " & item i of mySounds
	display dialog "sounds " giving up after 5
end repeat
on makeSoundsTable()
	set soundList to {}
	repeat with aSoundFile in {"Basso.aiff", "Blow.aiff", "Bottle.aiff", "Frog.aiff", "Funk.aiff", "Hero.aiff", "Glass.aiff", "Morse.aiff", "Ping.aiff", "Pop.aiff", "Purr.aiff", "Sosumi.aiff", "Submarine.aiff", "Tink.aiff"}
		set end of soundList to quoted form of ("/System/Library/Sounds/" & contents of aSoundFile)
	end repeat
	return soundList
end makeSoundsTable

Here’s a similar tool I use for trying sounds in Yosemite. It finds whatever sounds are there, puts them in a menu, plays each one then runs the menu till you’ve had enough. The result is a list of paths to the sounds you played!


property prevCHOS : null 
set mySNDS to {} 
set systmSNDS to every paragraph of (do shell script "ls '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/'") 
repeat with eachDIR in systmSNDS 
repeat with fylNAMs in every paragraph of (do shell script "ls '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/" & eachDIR & "/'") 
set end of mySNDS to (eachDIR & "/" & fylNAMs) 
end repeat 
end repeat 
set rprt to "Sounds you have tried:" & return 
set usrCHOS to prevCHOS 
repeat until usrCHOS is "false" 
set usrCHOS to (choose from list mySNDS with prompt "Choose a sound to hear..." with title "MY SYSTEM SOUNDs" default items {prevCHOS}) as text 
if usrCHOS is not "false" then 
set prevCHOS to usrCHOS 
set sndPTH to "/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/" & usrCHOS & "/" 
do shell script "afplay '" & sndPTH & "'" 
set rprt to rprt & sndPTH & return 
end if 
end repeat 
return rprt

And if you REALLY want to see ALL the sounds, use this!


property prevCHOS : null
set mySNDS to every paragraph of (do shell script "mdfind 'kind:audio'")
set rprt to "Sounds you tried:" & return
set usrCHOS to prevCHOS
repeat until usrCHOS is "false"
	set usrCHOS to (choose from list mySNDS with prompt "Choose a sound to hear..." with title "MY SYSTEM SOUNDs" default items {prevCHOS}) as text
	if usrCHOS is not "false" then
		set prevCHOS to usrCHOS
		do shell script "afplay '" & usrCHOS & "'"
		set rprt to rprt & usrCHOS & return
	end if
end repeat
return rprt

Hi.

You may find this faster:


set mySNDS to paragraphs of (do shell script "find '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds' \\( -type f -not -name '.*' \\) | sed 's|^/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/||'")

Hello every one,

it is my first post here.
I wanted to make a merge of all previous posts :

  • sound files from /System/Library/Sounds/
  • sound files from /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/
  • report of which files have been played
  • Sound played two times
  • Repeat list of choice until we click on cancel button

My addition : two handlers that may or may not be useful.

  • getSystemSoundsAliasList : returns a list of alias of system sound files
  • playSound : play the sound file in parameter

So, the code :


---------------------------------------------------------------------------------------------------------------------------
-- File name	:	sounds.applescript
---------------------------------------------------------------------------------------------------------------------------
-- Description :	List of all system sounds to make a choice and return the tried ones.
---------------------------------------------------------------------------------------------------------------------------
-- Remarks	:
--				- From ideas of McUsr, Mr. Science and Nigel Garvey of macscripter.net
--				- tested on Mac OS X 10.12.6
---------------------------------------------------------------------------------------------------------------------------


# Main handler
on run
	set linesOfSelectedFiles to ""
	
	# We get the list of system sound as alias
	set mySystemSoundAliasList to getSystemSoundsAliasList()
	
	# We build a list of system sound file name to choose from
	set mySystemSoundNameList to {}
	repeat with i in mySystemSoundAliasList
		set end of mySystemSoundNameList to displayed name of (info for i)
	end repeat
	
	repeat
		
		# We ask the user to pick a sound file
		set selectedSoundFileName to choose from list mySystemSoundNameList ¬
			with title ("Play system sounds") ¬
			with prompt ("Select a sound to play")
		
		if selectedSoundFileName is false then exit repeat
		
		if linesOfSelectedFiles is not "" then set linesOfSelectedFiles to linesOfSelectedFiles & return
		
		repeat with i in mySystemSoundAliasList
			if displayed name of (info for i) is equal to (selectedSoundFileName as text) then
				repeat 2 times
					playSound(i as alias)
				end repeat
				set linesOfSelectedFiles to linesOfSelectedFiles & POSIX path of i
				exit repeat
			end if
		end repeat
	end repeat
	
	return linesOfSelectedFiles
	
end run


-----------------------------------------------------------------------------------------------------------
--                                                     FUNCTIONS
-----------------------------------------------------------------------------------------------------------

(*
Nom			: getSystemSoundsAliasList 
Description	: returns a list of alias of system sound files
return		: a list of alias of system sound files
*)
on getSystemSoundsAliasList()
	
	set aliasList to {}
	
	set aliasSystemFolder to path to library folder from system domain
	set aliasSystemSoundsFolder to ((aliasSystemFolder as text) & "Sounds") as alias
	
	tell application "Finder" to set nameList to name of every item of aliasSystemSoundsFolder
	
	repeat with i in nameList
		set end of aliasList to ((aliasSystemSoundsFolder as text) & (i as text)) as alias
	end repeat
	
	
	set mySNDS to paragraphs of (do shell script "find '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds' \\( -type f -not -name '.*' \\)")
	
	repeat with i in mySNDS
		set end of aliasList to (POSIX file (i as text)) as alias
	end repeat
	
	
	return aliasList
	
end getSystemSoundsAliasList

(*
Nom				: playSound 
Description		: play the sound file in parameter
aliasSoundFile		: an alias of the sound file to play
return			: NOTHING (the sound is played)
*)
on playSound(aliasSoundFile)
	do shell script ("/usr/bin/afplay " & quoted form of (POSIX path of aliasSoundFile) as text)
end playSound

PS: this is my first post but I’ve been reading this site for a long time. Let me thank you all for this most valuable resource. :slight_smile: