Filed under: Features, How-tos
Mac Automation: Looping Workflows
Sometimes when working with Automator, you might want a workflow to loop (or go back to the first step and continue to run through the workflow). Automator includes an easy-to-use "Loop" action, and in this Mac Automation post, I'm going to show you how to use it.Let's take a previous workflow that I wrote about: iCal to-dos. In this how-to, we got iCal to-dos sent to your mobile device via a simple workflow and e-mail. The method that I wrote about required you to send an email (and rely on mail rules) in order to retrieve your to-dos. However, with the looping action in Automator, you can easily automate this process.
Let's first build out the workflow by placing the following actions together (in the same order):
- Find Calendars In iCal
- New Mail Message
- Send Outgoing Messages
- Pause
In the "Find iCal Items" action, select "To Dos" from the "Find" drop-down menu. In the "Whose" section, select "Due Date" from the "From" box and "Today" from the second box. You can deviate from the instructions on this step and use the settings that allow you get the most use out of this workflow (for instance, you can select any interval of time you want, etc.).
In the "New Mail Message" action, enter your email address in the "To" field -- this is the address that your ToDo list will be sent to. Fill in a descriptive subject line like "My ToDo Items for Today" or something similar. Be sure to select an email account that your remote device can access.
Here's where we will differ from the original workflow -- instead of setting up mail rules, we will add the "Loop" action to the end of this workflow -- this will make the to-do process totally automatic.
When you add the Loop action, you'll notice that there are several options included to give you control on how the workflow will be looped. In the first drop-down box you will notice that there are two options: Ask to continue and Loop Automatically. The ask to continue option will prompt the user to accept a continuance of the workflow; the user will be asked to select either "Continue" or "Don't Continue" from a pop-up dialog.
We will be using the "Loop automatically" option for this workflow. When you select this option you will be asked to specify either how many times or how many minutes. This limitation keeps you from accidentally creating an infinite loop (not Apple's address, but a programming error known as an infinite loop).
This is where the Pause and Loop actions work together. If you wanted your to-do list to be sent 2 times a day, you could input "2 times" in the Loop action, and specify 43,200 seconds (half of 24 hours in seconds) for the Pause time. This would cause your to-do list to be sent twice a day, then stop.
As you can see, Automation on the Mac is powerful, and the loop action adds to that power. We'll be using the loop action more in future Mac Automation posts, so be sure to stay tuned. And if you want to read more about Automator then be sure to visit our Mac Automation page.

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
Jesse said 4:38PM on 1-26-2009
When I try and use the pause action it only lets me set a max of 59
seconds. Far less then the 43,200 in the example. What gives?
Reply
Martin said 11:37AM on 1-26-2009
I have yet to find a decent use for Automator outside of the kind of simple task I can do with Quicksilver, such as emailing selected/specified Finder items.
Reply
jsw said 2:38PM on 1-26-2009
Well, I used it to quickly set up a mix of Applescript, Shell Script, and Finder actions that I use for backups. And there are some decent third party Automator actions that I use to sync a folder on my computer with one on my iPod.
All things that could be done another way, but Automator let me do them very quickly and easily.
Zimmie said 7:45PM on 1-26-2009
I use it to do batch processing of web server logs to pull out the number of times a given file has been downloaded or that sort of thing. Yeah, it's something I could do with a shell script, but that would be more effort for something that isn't significantly better.
dave said 11:03AM on 1-27-2009
Like others have mentioned there are a lot of things that automator can do more easily (for most at least) that can be done by other means.
Although I have moved it to applescript but I did have a backup process of iCal and Address book in automator.
Actions like downloading certains types of files from a website/feed without even opening a browser is pretty useful
One thing though is that I wish apple would make it possible to see the script behind the automator action/workflow so that beginners can look into applescript
Martin said 7:28AM on 1-27-2009
I made a couple of workflows in the past - one to back up Mail archives, for example, but otherwise I've used it little. What I'd like to do is get Mail attachments, send them to the downloads folder, unzip them if they're zipped, open Word documents, run a couple of macros, save them and close them again, then quit Word. Now THAT would be useful!
dave said 11:03AM on 1-27-2009
Martin.
Most of that can be easily be done with at least applescript. Not sure about office and automator/applescript as I dont use it but at the very least you can unzip files and open them in their default application