How do I make Mail.app quit after iCal sends an alert?

iCal uses a built in script file to email reminders through Mail.app. It works great, but I don't use Mail.app for my main email account, just for sending calendar notifications.

So, Mail.app opens and sends the alert, but then it stays open.

I've tried to edit the Apple script file to make it quit Mail, but that doesn't seem to work.

Can anyone offer some advice?


Let's do it the right way...

Set a new calendar event up after your email, and have it run a applescript... The script would consist of one line:

tell application "Mail" to quit

I believe that should take care of your issues....


I figured out a tricky way to do it. I'm going to make a couple assumptions: you are using IMAP and know your way around the Finder and AppleScript. I think it might work for POP mail too, although I'm not using POP mail so I'm not sure of the folder structure

Word of warning: this will trigger every time you send an email with Apple Mail. I presume this doesn't matter since you only use it for sending iCal alerts.

  1. Look in your ~/Library/Mail folder for your account folder. Will be labeled IMAP-login@mailserver
  2. There should be a folder named INBOX in there. Or if you're using gmail, it might be labelled [Gmail]. It all depends how IMAP mail is configured. In that folder you should have a Sent folder. Mine was named Sent.imapmbox. Maybe it's Sent Mail.imapmbox for gmail
  3. Inside that folder there should be a Messages folder. We want to attach a folder action to that folder
  4. Right click the Messages folder, and find Folder Actions Setup in the Services menu. (Might differ if you're not using OS X 10.6 Snow Leopard.)
  5. Attach a script to that folder. Use the one named add - new item alert.scpt for now.
  6. Select the script in the right pane. Click the Edit Script button.
  7. Replace the script contents with the following:

    on adding folder items to this_folder after receiving added_items
       try
          tell application "Mail" to quit
       end try
    end adding folder items to
    
  8. Save the script as quit - apple mail.scrpt or whatever.

Now whenever an email is sent with that account and the sent mail moved to this folder, this script will activate and quit the Mail application! I tested this and it worked with my computer.

Alternatively, you could use MailActOn to set up and Outgoing mail rule that runs a script. (Mail only supports incoming mail scripts). That costs money though. I suppose if you cc: a mail account configured in Apple Mail you could set up an incoming mail rule…