Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Audible Mail alerts and fast user switched accounts Apps
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.

[robg adds: Before proceeding, you should (a) be comfortable in Terminal editing files that could break your system if damaged, and (b) understand that this hint introduces some level of security risk to your machine. I haven't tested this one, so you're on your own -- proceed at your own risk.]

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.

Now, for any user with a rule set up to use the script, when a message arrives matching the mail rule, the computer voice will announce it -- even if another account is active, or the computer is at the login screen. Note that running anything as root potentially introduces a risk, since permissions restrictions aren't in effect for that process. If there is an unknown bug or security hole in say or the SpeechSynthesis framework, or if my implementation has overlooked a vulnerability, using this hint could cause problems. Hopefully, that won't be the case, but you should understand that risk before implementing this hint.
    •    
  • Currently 1.00 / 5
  You rated: 1 / 5 (2 votes cast)
 
[5,780 views]  

10.4: Audible Mail alerts and fast user switched accounts | 0 comments | Create New Account
Click here to return to the '10.4: Audible Mail alerts and fast user switched accounts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.