Triggering Application Launches with Automator

Introduction

On this week's episode of Mac Power Users with Geoff Barrall, Geoff shared one of my frustrations when using iTunes to share a media library. As I've discussed on the show, I have a Mac mini running 24/7 at my home and one of the advantages is that if I keep iTunes running on that machine I can share content with all the Apple TVs and other devices in my home. The problem is, after a while and for no apparent reason, my Apple TVs have trouble connecting to the iTunes library. Usually the answer is to simply quit iTunes on the Mini and relaunch. But this is a real pain every time I want to use iTunes because I have to either remote access into the Mini or dig out a keyboard and mouse. I've found that if I can automate the process of quitting and restarting iTunes once a day things seem to work much better.

There are a number of tools you can use to automate launching and quitting applications. Keyboard Maestro would be an excellent choice, but requires third party software. This tutorial will show you how to automate quitting and relaunching an App using an Automator action triggered by an iCal event.

Create a New Automator Action

Open Automator (by default Automator can be found in your Applications folder) and choose the Calendar Alarm type for your document.

Create a New Automator Action

Choose Quit Application Action

In this example, we're going to assume iTunes is currently running, but this action can be modified depending on your use. So, the first step would be to quit iTunes. In the Action LIbrary, under the "Utilities" category, choose Quit Application acton and drag it into the window to start building your workflow. You an also type "Quit Application" in the search box to quickly filter actions.

Choose Quit Application Action

Select The Application to Quit

Choose the Application you wish to quit when running your workflow. In this case, I'll choose iTunes. Since I do not want any user interaction and I don't need to save changes, I will uncheck the box next to "Ask to save changes."

Select The Application to Quit

Pause to Allow Application to Quit

Because it can take a few seconds for an application to quit, I like to pause the workflow for a few seconds to make sure iTunes has had a chance to fully quit before I attempt to re-launch it. So I'll build a pause in the workflow. You can find the Pause action under the "Utilities" library or search. Drag the pause action into your workflow and specify the number of seconds. Depending on the speed of your machine, 5-15 seconds should be plenty.

Pause to Allow Application to Quit

Relaunch the Application

For this workflow, I want to relaunch iTunes. In the Action LIbrary, under the "Utilities" category, choose the Launch Application acton and drag it into the window to continue building your workflow. You an also type "Launch Application" in the search box to quickly filter actions.

Once in place, select iTunes from the list of Applications.

Relaunch the Application

Save Your Workflow

This simple three-step workflow is ready to be saved. Choose Save form the File menu and choose a name for your workflow.

Save Your Workflow

Edit your Calendar Event

If you don't already have a calendar setup for Automator Actions, you'll see one has been created for you in Calendar.app with a new event added at the current date and time. You can now edit your calendar event to specify the actual date and time you want the workflow to run, and if you desire, setup a repeating schedule. For example, I set mine to run every day at 5:00 a.m because I know people are unlikely to be streaming from my iTunes library at that time.

So as to not have 365 "Relaunch iTunes" events on my calendar, I choose to keep this as an event only on my Mac mini's local calendar that doesn't sync with my other devices. You can also make the event appear less obtrusive by editing the name, duration or color.

Edit your Calendar Event

Modifying this Workflow

Now that you know how to create workflows triggered by iCal events, you can modify this as needed. For example, if you wanted to launch an App for a specific period of time and then quit it, you would essentially create this workflow in reverse with a longer pause. I use this once a week when I run MailSteward to archive my email. The possibilities are endless.