Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mail Applescript "set new mail sound" -> Apple Event handler failed

The following Applescript segment works in Snow Leopard and fails in Lion with "AppleEvent handler failed. number -10000"


tell application "Mail"

set new mail sound to "Glass"

end tell


In addition, the Apple-supplied, Mail Applescript for gathering Mail information "Display All Accounts and Preferences.scpt" fails

(again with "AppleEvent handler failed. number -10000") on the line


set displayString to displayString & my formatFields("New mail sound", new mail sound) & return


The Console Log reports the following error.



Mail: [<MailApp 0x7fd6a9e009a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key newMailSound.


The Mail Applescript property "new mail sound" appears not to be recognized correctly.


I do not have any Mail plugins. Several additional sounds have been added to the system sound set. Mail reports no problems using them.


Under Snow Leopard, I used the same Applescripts (fired off by iCal) which turned on/off Mail's New Mail Sound depending on the time of day, i.e. I set the new mail sound to be "Silent Alert" in the evening and restored it to my default new mail alert in the morning. Any guidance as to what might be wrong and how to solve this problem would be very welcome.



iMac, Mac OS X (10.7.3)

Posted on Apr 16, 2012 6:41 AM

Reply
Question marked as Best reply

Posted on Apr 16, 2012 2:46 PM

The following script might act as a workaround:


tell application "Mail" to activate

tell application "System Events" to tell process "Mail"

keystroke "," using {command down} -- open Mail preferences

clickbutton 1 of tool bar 1 of window 1 -- General

clickpop up button 5 of group 1 of group 1 of window 1

keystroke "Glass" & return

keystroke "w" using {command down} -- close Mail preferences

end tell


Since the above script uses GUI Scripting, you must enable the Accessibility Frameworks by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane.

7 replies
Question marked as Best reply

Apr 16, 2012 2:46 PM in response to Jim Downward

The following script might act as a workaround:


tell application "Mail" to activate

tell application "System Events" to tell process "Mail"

keystroke "," using {command down} -- open Mail preferences

clickbutton 1 of tool bar 1 of window 1 -- General

clickpop up button 5 of group 1 of group 1 of window 1

keystroke "Glass" & return

keystroke "w" using {command down} -- close Mail preferences

end tell


Since the above script uses GUI Scripting, you must enable the Accessibility Frameworks by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane.

Apr 16, 2012 3:50 PM in response to Jim Downward

Here's an improved version of my previous script:


set myDefaultNewMailAlert to "New Messages Sound" -- enter the sound of your choice

set theEvening to 18 * hours-- 6 PM (adjust to fit your needs)


set volume with output muted

tell application "Mail" to activate

tell application "System Events" to tell process "Mail"

keystroke "," using {command down} -- open Mail preferences

clickbutton 1 of tool bar 1 of window 1 -- General

clickpop up button 5 of group 1 of group 1 of window 1

if (time of (current date) > theEvening) then -- no alert in the evening

keystroke "None" & return

else

keystrokemyDefaultNewMailAlert & return

end if

keystroke "w" using {command down} -- close Mail preferences

end tell

delay 2

set volume without output muted


Message was edited by: Pierre L.

Apr 16, 2012 4:13 PM in response to Jim Downward

Instead of using AppleScript-Commands or GUI-Scripting you could edit Apple Mail's Preferences by using defaults write to set another MailSound

defaults write com.apple.mail MailSound "/System/Library/Sounds/Tink.aiff"

This is a quick and direct way... to be 100%sure that this setting is enabled right away, I would restart Mail or open/close the prefs window quickly to make Apple Mail realize the changes in the plist

Apr 17, 2012 6:57 AM in response to Jim Downward

Thanks for the variety of suggested workarounds. I have also filed a bug report. I had hoped that the error I encountered would not turn out to be an Applescript bug but rather would be a documentation error caused perhaps when the Lion rewrite of Mail changed the property name. In that event, all that would be needed would be to find the new, and correct, property name.

Mail Applescript "set new mail sound" -> Apple Event handler failed

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.