Apple Mac OS X tips and tweaks
Use Automator announce birthdays
This article for the Apple Mac isn't really about birthdays and it's really a simple introduction to Automator, a great utility that is bundled with OS X. Automator is a sort of progamming tool, but it is an unusual one because you don't need to know anything about programming in order to use it. Lots of actions are provided with it and you simply choose which actions you want to perform and the order in which they are to be executed. It's mostly done through drag and drop using the mouse and you rarely need to type anything in. Yet you can create applications that perform complex tasks and it is especially useful for repetitive tasks. The example application built in this article checks to see if there are any birthdays in your iCal calendar when you log on to your Mac and if there are, it speaks them out loud to remind you to send birthday wishes. It's trivial, but it shows how Automator works quite well.
Using Automator actions
Start Automator in the Applications folder and make sure that Actions is selected in the top left corner. Select Calendar under Library and the second list displays all the actions you can perform with iCal. Click and drag Find iCal Items from the list and drop it on the large pane on the right. Expand it if necessary by clicking the little triangle on the left of the title bar so you can see the contents. Select Any content in the pop-up menu and then enter birthday in the box.
If you read the description of the Find iCal Events action in the bottom left corner, you'll see that the the input is iCal calendars and the result is iCal events (among other things). What this action does is to check iCal calendars and if there are any events that match the condition we set - if it contains the word 'birthday' - then it will output these events.
As it stands, it will output every birthday in the calendar, which could be quite a lot! Click the plus button on the right and set the second condition to Date starting and is today This means that it will only output an event if it contains 'birthday' and it is today.
Click and drag Event Summary from the actions list and drop it below Find iCal Events. In the description of this action you'll see that it accepts iCal events as input and that it outputs text. What text? Let's see. Click the Utilities category in the Actions list and drag and drop View Results from the second list and drop it on the right.
Click the Run button in the top right corner and if there's a birthday today (add one to iCal before you start for testing purposes), you'll see the text in the View Results window. This is great, but what can we do with it?
Filter the text
The View Results action is just for testing your Automator workflows and it's perfect for checking the output of an action. We don't need it in the finished program though, so delete View Results by clicking the cross at the right-hand side of it.
View Results showed that a lot of text is produced from the previous action and not all of it is useful. The bit that we want is the summary. In the screen shot it says "Summary: My birthday". The summary text is the title of the event in the iCal calendar and for people's birthdays you'll have Bob's birthday, Sue's birthday or some similar text. This is exactly what we want.
Select the Text category in Automator's Actions list and then click and drag Filter Paragraphs from the list of actions to the main window. Expand it if necessary and select Return paragraphs that begin with, and enter Summary into the box. This action will strip out all the text except the line that starts Summary. Now drag the Speak Text action to the workflow and drop it at the bottom. This speaks the text that is passed to it.
Make sure there's a birthday today in iCal and run this Automator workflow by clicking the Run button in the top right corner. You'll see that it speaks all birthdays occuring today. What if there isn't a birthday? Make sure there's no birthday today in iCal and then run the Automator workflow - it stops with an error because no text is passed to the Speak Text action and it doesn't know what to do.
The workflow should do nothing if there are no birthdays, but there doesn't appear to be a way to do this. We must fudge some workararound so that when there are no birthdays, Speak Text says nothing, but doesn't stop with an error message.
Use the clipboard
One way around the Speak Text problem is to ensure that there is always some text to speak, even if there are no birthdays. Drag the Get Specified Text action from the Text category and drop it at the top of the workflow. You'll see a box where you can enter some text. Type three or four spaces into it. Now from the Utilities action list, drag Copy to Clipboard and insert it just after Get Specified text. Then drag Get Contents of Clipboard and insert it just before Speak Text.
What this workflow now does is to add some text to the clipboard - blank spaces - then check iCal for birthdays. The iCal events, if any, are filtered to get the subject line. Then the clipboard text - blank spaces - is added to this. Of course, blank spaces in between words are not spoken and are silent. What this means is that Speak Text always has some text to work with. If there are no birthday events then it simply has blank spaces to speak and so says nothing. It gets around the problem of not having any text to speak.
Create the app
Go to Automator's File menu and select Save. It is saved as a workflow file and this means that you can load it at any time and edit it, change things around and save it again. Now select File, Save As and this time select Application in the File Format list. The file is saved as an executable program. It can be run like any other app by double clicking it.
Now here's the useful bit. Go to the Apple menu then System Preferences. Click Accounts and then the Login Items tab. Drag the app you just created from the desktop or Finder window wherever you saved it and drop it on the Login Items list. This means that it will be run every time you log in or start the Mac. Log in and any birthdays occuring today will be spoken out loud!
Of course, you don't have to check for birthdays and you could check for any events and announce them. You could even get all the events for today and speak them out loud if you wanted to.
Go to Apple Mac and OS X tips and tweaks index...