4/19/13
5:00 am

MacMost Now 854: Using Automator With Calendar and Mail

Learn about some of the actions in Automator that control the Calendar and Mail app. Build a workflow that will search your events, summarize them as text, and convert that text to an audio file. Then Mail can send it as an email message.

Video Transcript (Click to Expand)
Hi this is Gary with MacMost Now. On today's episode let's look at some of the Calendar functions inside of Automator.

First a quick look in my calendar here. I'm using Mountain Lion so it is Calendar, not iCal, and I've just got a couple of appointments here that we can see this week.

Now let's switch over to Automator. In Automator we are going to create a Workflow but you can create an application as well. We are going to access some of the calendar functions in here.

So for instance go into Calendar and we see them all here under the Calendar subheading Library. Let's go and do the Find Calendar Events. We are going to drag that into the Workflow. Here we can do a little search. We can find events where all the following are true.

Let's set it for Date starting is this week. So it is going to find all the events for this week. Click on the results here and we can see the results of that. So I can run this and I can that it will find those three events that I showed you before.

Okay, so let's do something with these. Let's hide these results here and let's go and do something called Event Summary.

Event Summary, if you click on it we can read the description here, creates a summary of the calendar and the events passed into it. So let's drop that here. You can see there is a link between the two of them. It takes the output for this first action into the input for the second action here. We can see results here. Let's run it and see what we get. We can see here it actually creates some text. This text basically is reading off those three events and some information about them.

So where can we go from here. Well, what would be nice is if you can actually hear the summary of those events. Say if you want to have something read to you while you are driving to work in the morning you can actually use something here in the Library where it is going to speak the text. Let's search for speak and it will be Speak Text. So put that here and it will take the output from the event summary and it is going to speak it here. We can pick which voice we are going to use. We will just use the default and then we should be able to hear it when we run it.

Now it would be nice to hear that while driving but this is going to just play it on our Mac. So let's do something a little different. Let's get rid of speak text here and say let's go down to the Text subcategory and there is a handy one here where it will do text to audio file. So it is similar. You can even see you could get the voice here just like before. But instead we are going to save it as a file.

So we will do CalTalk as the name of the file. We could save it to the Desktop but it is actually better to save it to a special folder that we create for this since you will be creating a lot of files every time you do this. So under Documents we will create a CalTalk folder and set it to there. Great!

So now when we run this it will just do that if we go into the Finder and we look under CalTalk you can see it has created this audio file that we can now play and hear. Here we output it from the Calendar.

So now let's go back into the Workflow here in Automator and let's do something else. Let's go ahead and email this. The mail actions aren't as straight forward but we can create a new mail message. Now what is going to happen is we want the output of this audio file action here to go into the new mail message.

What we are going to do is create a new mail message here at the top before we do anything else since we are not taking any input into this script here we are going to create this new mail message and we are going to send it to ourselves. Okay. We are going to attach a subject there. Nothing in the message. Now start a new mail message. So it is going to start Mail if Mail isn't already running. Then it is going to continue to find the Calendar events that we want. Then it's going to create the Events Summary, save it to an audio file and then the output from this text to audio file is going to be a link to that audio file.

So we can look here and under Mail we can add an attachment to the Front Message. We want to add this file to that message. Let's look what happens now when we run it.

So you can see what happened here is that it opened up Mail, created a new message, put the subject in there and it created the audio file and then it attached it to this email.

Now we could stop there and just have it be a two-step process. One is you run the script and the other is you finish sending the email. Well let's have it send the email anyway and since there isn't an action we are going to have to cheat a little bit and you record an action.

Recording an action will record the steps that you perform by mouse and keyboard.

So let's hit record now and then let's switch over to Mail and then in Mail I'm going to Command shift D on the keyboard, which is the shortcut for send. Now there is no message to be sent here so I just get a little error beep. That's okay because it recorded the action anyway.

If I go back to the Workflow I can see it recorded me switching to Mail which I don't need because after you add an attachment to the front message it's already going to be in Mail so I just deleted that one. Selected it and deleted it. Then it is going to do press Command shift D which should send the email.

Now if I run this it should do everything that it did before but also finish by sending the message.

One of the problems with doing a manual command like pressing shift Command D under a watch me do action here is that sometimes the script hasn't finished doing this or Mail itself hasn't finished doing these actions and the script goes ahead and issues that keyboard command and Mail isn't ready. So sometimes it will send and sometimes it won't because that command gets sent too early.

So I'm going to search for the pause function here. Put a pause just before this and build in a five second pause. This won't guarantee that it gets sent but it should get sent most of the time. So let's run it now. We can see that it creates the message, creates the attachments, and then after a few seconds it should send it. There it goes.

Now when I check my email here it is. I've got the email message, got the attachment and I can play it right here in Mail. Now I really can listen to it in the car because, of course, I get my email on my iPhone and the attachment is there.

So your last step may be to either save this as a Workflow or if you want you can save it as an app so you can put it somewhere you can easily run it like in your Dock and then it should run by itself. Grab your weekly events. Of course you can alter what you do here. Find Events with the date starting today, for instance, or you can set a whole bunch of other date parameters and you can add additional parameters like for instance that the event is marked as something or has no or an attending name. Anything you want in here. There is all sorts of different things you can put into the search for the event so you only get certain events from certain calendars meeting certain criteria.

Hope you found this useful. Until next time this is Gary with MacMost Now.

Comments: 5 Responses to “MacMost Now 854: Using Automator With Calendar and Mail”

    jeffrey
    4/22/13 @ 12:39 pm

    I followed your directions exactly yet it does not send the email. I have increased the pause to 15 seconds with still no luck. Any suggestions?

      4/22/13 @ 12:51 pm

      Play around with it. With programming, you sometimes have to “play detective” and troubleshoot problems. Is it switching to Mail? Does it work if you manually click Send? Investigate and experiment.

    John C Stires
    4/25/13 @ 12:12 pm

    Where would we be without you, Gary? As always, thank you for sharing your knowledge with us and in such a great, understandable, interest inducing format.
    js

    Clinton
    4/25/13 @ 1:10 pm

    What js said. Thanks Gary – I had no idea this was available.

    Brilliant!

    John C Stires
    4/25/13 @ 2:22 pm

    MAIL:
    “Shift-command-D” is shortcut for ‘Deliver’ is more intuitive than “Shift-Command-D” for ‘Send’, IMHO.
    Shift-command-A = Attach file, etc.
    Thanks again for your wonderful Keyboard Shortcut list at
    http://macmost.com/printable-mac-keyboard-shortcut-page-for-mountain-lion.html
    Thanks again,
    js

Comments Closed.