When Mail.app is set to check for mail automatically, a logged-in user that may not be sitting at the computer may still be alerted to the arrival of new mail by the "New Mail" alert sound. Unfortunately, in 10.4, this alert is not audible if the account has been switched to the background using Fast User Switching. This hint describes a potential workaround, using a Mail rule attached to an AppleScript that invokes the say Terminal command with special privileges.
The script isn't really the point of the hint (and many more elaborate Mail scripts have been published on this site), but the simple one below hopefully will be enough to demonstrate the basic idea. Paste it into a Script Editor document, and save it as a script somewhere accessible to all users that may make use of it.
using terms from application "Mail"
on perform mail action with messages messagelist
set user to short user name of (system info)
set phrase to quoted form of ("New message for " & user)
try
do shell script "sudo /usr/bin/say " & phrase
end try
end perform mail action with messages
end using terms from
Next, add a new rule in Mail.app through Mail -> Preferences -> Rules -> Add Rule, defining criteria for messages to be announced, set to Run AppleScript, and choosing the above script as the target. Because of the way the script is written, a few more steps are required to make the setup functional, by enabling users to execute sudo /usr/bin/say without a password.
There may be easier ways to run an executable as root without manually inputing a password, but editing the sudoers file makes it possible to do so without hard-coding the password into the script, while at the same time disabling the potentially destructive -o option of say.
Warning: Don't attempt the next step unless you know how to restore an /etc/sudoers file from a backup, using single user mode or other means, keeping in mind that ownership and permissions of this file are critical to its functioning.
Be sure to back up the /etc/sudoers file, then begin editing the /etc/sudoers file by logging in to an "admin" account, and entering sudo visudo. After entering an admin password at the prompt, type in an uppercase G to move the cursor to the last line of the file, then a lowercase o which switches to edit mode and adds a new line. Then add this line to the file, substituting a user's short name for username:
username ALL= NOPASSWD: /usr/bin/say, !/usr/bin/say *-o*
Additional users can be included as a comma delimited list (ie. substitute user1, user2, user3 in place of username. Exit edit mode by hitting the Escape key, then save the changes and quit by typing :wq, or bail out without saving by typing :q!. That should be all that needs to be done.
Comments (0)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20060922104922264