Randomize Apple Mail notification sounds

Nov 15, '07 07:30:09AM

Contributed by: TheCrunge

While looking for some unique and funny new email notifications for Mail, I found there were too many to choose just one. I thought it would be nice to dump a bunch of .wav files into a folder and have them randomly play when new messages arrive. Here's how:

  1. Place a bunch of .wav (or other supported audio files) in your user's Library/Sounds folder
  2. Paste the code below into an AppleScript and save it as .scpt file somewhere (~/Library/Scripts is a good place):
    tell application "Finder"
      set thecount to (count items in folder "Sounds" of folder "Library" of (get home))
    end tell
    
    set theValue to (do shell script "number=$(( `date +%s``echo $RANDOM` % " & thecount & " + 1)); echo $number") as number
    
    tell application "Finder"
      set NotifyName to (get name of item theValue of folder "Sounds" of folder "Library" of (get home))
    end tell
    
    tell application "Mail"
      set new mail sound to NotifyName
    end tell
  3. Create a rule in Mail.app that triggers this script for all incoming mail. Add the rule to the top of the rules list. I use it as rule number one in the list.
As for where to find alert sounds, there are a number of good ones here.

[robg adds: One of the queue review team suggests the following as a simpler version of the above script:
tell application "Finder"
    set NotifyName to (get name of (some item of folder "Sounds" of folder "Library" of (get home)))
    end tell
tell application "Mail"
    set new mail sound to NotifyName
end tell
He points out that you must have a rule to play the sound, or you won't hear anything when the script runs. I have not tested this one myself, nor can I vouch for the legality of any of the sounds that may be posted on the above site (it wouldn't load for me while I was writing up the hint).]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20071101191424294