randomize alert sound?

Maybe I’m not searching for the right terms…

Has no one come up with a method to randomize OSX’s alert sound?

I’d like to have the alert alternate between a batch of my own AIFFs.
The goal would be to make the alert surprising. (you tune it out if you hear the same one over and over)

Maybe every five minutes just change what sys prefs has as its alert?
(though It sounds like scripting sys prefs is no picnic)

I had one idea where I would name all of the different AIFFs with the same name (and store them in subfolders) and then every so often have one of them overwrite the one in /System/Library/Sounds. But that seems clunky.

I’m open to ideas. Thanks.

random number from 1 to 10

will this help?
(unless you meant to do this when you wrote that you would over-write the sound file)

I think I can handle randomizing, its getting the Sound sys. pref to accept the whatever gets chosen.

--assuming "Frog" is your default sound
set ifolder to "Leopard:System:Library:Sounds:"
set ifile to "Leopard:System:Library:Sounds:Frog.aiff"
tell application "Finder" to set name of file ifile to "Frog2.aiff"
tell application "Finder"
	set thelist to every file in folder ifolder
	set rn to random number from 1 to 10
	set namex to name of item rn in thelist
	set name of item rn in thelist to "Frog.aiff"
	set name of file ifile to namex
end tell

my idea was this but renaming fails because of permissions problem. You have to use do shell script and “administrator privileges”.

here is an example of renaming:


set ifile to "Leopard:System:Library:Sounds:Frog.aiff"
set ifile2 to "Leopard:System:Library:Sounds:Frog2.aiff"
set ifile to quoted form of (POSIX path of ifile)
set ifile2 to quoted form of (POSIX path of ifile2)
set thecmd to "mv " & ifile & " " & ifile2
do shell script thecmd with administrator privileges

What exactly do you want going on here:
set thecmd to "mv " & ifile & " " & ifile2

the idea is to choose a certain sound in system preferences and rename randomly all desired sounds to that name.
The privileges issue is no problem if you put your sounds in ~/Library/Sounds.

I’d prefer to use the cp command, which copies the files and keeps the originals untouched

Sorry, I’m missing it.
How could more than one file with the same name exist in the same location?

no problem.
Immagine you have three sounds: s1, s2, s3.
Duplicate s1 and name it s4
Choose s4 as alert sound.
Duplicate s2 to s4 with replacing
Duplicate s3 to s4 with replacing
etc.

OK, I think I got it.

Does this have to be done via shell scripting?

AppleScript can’t duplicate and rename simultaneously, the shell can

thanks, StefanK for doing all the explaining!!:slight_smile: Its fun to write a script, boring to explain it.