Using Mail.app with multiple users — using AppleScript!

OK, this is pretty brilliant — and SO simple.

Here’s the setup: my wife and I share a Mac at home. For memory reasons, among others, I don’t want to use Fast User Switching, and because of my automated tasks, I don’t want the primary account to ever be logged out. So all many of our programs need to be set-up for two different users. Firefox has user profiles, that once configured, works perfect. Mail.app has no such thing. What I decided to then, was write an AppleScript that would switch Mail.app between users for us. This example is for two users, but it could be edited for more. Here’s how to use it:

  • Setup Mail accounts for each user
  • Modify the script to prompt for each user you have, and reference their account name
  • Replace your Mail.app dock icon with a link to your AppleScript (you can even give it the Mail.app icon)
  • Whenever you launch Mail, you’ll be asked which user you want to use
  • Even better than that, you can switch users just by clicking the Mail icon in your dock again. You don’t even have to close down Mail!

The result looks like this whenever you invoke the script, and launches/reconfigures Mail within two seconds. Set the delay to longer if Mail.app takes longer to start on your Mac.

The code is dead simple, and took me only moments to put together. Note that the delays and the order in which things are done is important so that it doesn’t hang waiting for Mail to start if its not already open.

-- Mail Account Chooser, by Jon Wise
-- Add user profiles to Mail.app
display dialog "Choose the Mail account to use" buttons {"Jon", "Elizabeth"} default button 1 with icon note
if the button returned of the result is "Jon " then
  tell application "Mail"
    activate
    delay 2
    set enabled of account "Elizabeth Home" to false
    set enabled of account "Jon Home" to true
  end tell
else
  tell application "Mail"
    activate
    delay 2
    set enabled of account "Jon Home" to false
    set enabled of account "Elizabeth Home" to true
  end tell
end if

Advertisements