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

6

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?

Chuy77

Posted 2010-03-13T04:07:24.083

Reputation:

Answers

4

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....

Benjamin Schollnick

Posted 2010-03-13T04:07:24.083

Reputation: 4 313

1Wouldn't I have to add a new event after every iCal email notification to make that work?

I was actually trying to add the line above to the script iCal uses to send the email notification last night, but it just ignored it. Any idea why?

/Applications/iCal.app/Contents/Resources/Scripts/Mail.scpt – None – 2010-03-13T15:47:21.387

True... That would be an issue.... Where did you add it when you placed it in the script...? – Benjamin Schollnick – 2010-03-14T17:37:57.973

Ha...well, I put it at the end to start with, but it didn't do anything, so I've moved it all around. The email reminder still works no matter where I put it, but Mail refuses to close. – None – 2010-03-14T23:35:15.060

You know that with iCal you can add more than one action for an event? that could solve the problem. adding a little looping to run until the mail is sent then close. Or just write a script that sends a mail then close Mail.app could do the trick. I'm not use AppleScript at all, but maybe someone who knows it mare can enlighten us. – Philippe Gilbert – 2012-07-20T03:11:50.997

4

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…

ghoppe

Posted 2010-03-13T04:07:24.083

Reputation: 6 124

Thanks so much for the useful info!! Note that the steps for changing permissions and changing the owner of the new script could be skipped if you just log into your Mac as root. Still need to enable the root user to do this though. If you do decide to do all that via "su -", be sure to change your permissions back to their original settings when done, and re-hide your ~/Library folder as well. – None – 2012-07-19T14:53:30.843