PDA

View Full Version : Get Your Feet Wet with Automator



MTBlogBot2000
20th July 2010, 07:41 AM
<a href="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator00.jpg"><img class="alignright size-full wp-image-8023" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator00.jpg" alt="" width="215" height="215" /></a>Automator is one of Mac OS X's unsung heroes. Allowing you to automate an impressive list of functions - both those built into Mac OS and those added in by third party developers - it's a visual way of creating script-like custom operations without the need for any programming knowledge or experience. Most go on unaware of its existence in their Applications folder for the longest time, but there are many good reasons to get to know the little guy.

I'll give you a couple of examples of just how handy Automator can be in daily life. I've set up an Automator application (yes, Automator lets you easily create real <em>applications</em>) that opens every file, application, web site and remote machine I rely on each day at work, all from one dock icon I casually click as I walk away to make my first morning coffee. By the time I get back to start the day with mug in hand, it's all there. It even automatically closes a handful of favourite apps I've come to know as distractors.

Here's another. As a recording musician, every last MHz of CPU matters to me. When you're mixing a session, real time plugins can suck the life out of your Mac and if you could just squeeze an extra 2% of available headroom out of OS X, you would. Before I start or open a session, I run an automator application that not only closes all open applications (those visible in the dock), but even those services and menu bar items that can be closed only by manual termination from Activity Monitor (safe ones, of course). By doing this <em>once</em> and recording my keystrokes with Automator, I've turned it into something I can kick off and walk away from while I go and (again with the coffee) get fuelled up for a day in Pro Tools. <!--more-->
<h2>Basics</h2>
Let's learn some basics to get you started. We'll create applications that open apps and files, resize images and even one that watches you do things on your Mac, then repeats them.
<h3>Opening and Closing Apps</h3>
Open Automator and choose <em>New A</em><em>pplication</em> when prompted. You'll be greeted with the main Automator window, displaying a list of action categories in the leftmost column, then actions within that category in the column to its right. The blank area on the far right is the workflow area. It's the canvas into which you'll drag each action (in the order they'll be performed) from top to bottom.

<img style="margin-left: auto; margin-right: auto;" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator01.png" border="0" alt="Main Window" width="592" height="421" />

Select the <em>Utilities </em>category and drag the Launch Application action into the workflow area.

<img style="margin-left: auto; margin-right: auto;" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator02.png" border="0" alt="Automator02.png" width="592" height="421" />

Choose an application from the drop down list. Click <em>Run</em> in the toolbar and you'll see the selected app's dock icon come alive. Congratulations, you've created your first app! Save the app and try launching it from your Dock.

You can drag as many instances of <em>Launch Application</em> into the workflow area as you like, selecting a different application in each one, to launch as many apps in a single automator workflow as desired.

<img style="margin-left: auto; margin-right: auto;" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator03.png" border="0" alt="Automator03.png" width="305" height="222" />

To quit apps rather than launching them, choose <em>Quit Application</em> or <em>Quit All Applications</em> instead (also in the <em>Utilities </em>category).
<h3>Launching Files</h3>
Creating a workflow that launches files takes an extra step. From the <em>Files &amp; Folders</em> category, drag <em>Get Selected Finder Items</em> into the workflow. Click <em>Add</em> to specify a file location (can be a document, image, anything at all) and continue to add as many files in this way as you like.

Now drag <em>Open Finder Items</em> into the workflow below the specified files, choosing <em>Default Application </em>from the drop down menu.

<img style="margin-left: auto; margin-right: auto;" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator04.png" border="0" alt="Automator04.png" width="305" height="220" />

Now you can save and test your application!
<h3>Resizing Images</h3>
It's fun to automate image operations with Automator, and the ways you can interact with created Automator apps' icons make it very easy to apply the selected change to a batch of files. We'll start by creating an application that resizes images.

Select and drag the <em>Scale Images </em>action from the <em>Photos</em> category into the workflow area. When you try, you'll be prompted to choose whether you want Automator to create new copies of these files for preservation of the originals. Let's choose <em>Add</em> to see this in action.

<img style="margin-left: auto; margin-right: auto;" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator04b.png" border="0" alt="Automator04b.png" width="315" height="162" />

Automator has added the <em>Copy Finder Items</em> action to the workflow for you. From here you can select a destination for the copies from its drop down menu. In the <em>Scale Images</em> action, choose <em>By Percentage</em> and set to <em>60%</em>. Save the application. Let's see it at work. Drag the icon into the Dock or Finder toolbar. Select multiple images from Finder and drag them into the app's icon.

<img style="float: right;" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator05.png" border="0" alt="Automator05.png" width="55" height="30" />

You'll see Automator's gear icon in the menu bar (right) working away on performing your Automator operations (which won't take long if you've only selected a few images). After this disappears, your application has done its work. Browse to the destination folder you set in Automator and check the image size. Magic!
<h3>Recording Your Actions</h3>
<img style="float: right;" src="http://www.mactalk.com.au/wp-content/uploads/2010/07/Automator06.png" border="0" alt="Automator06.png" width="163" height="41" />

Here's a fun one to sit back and watch. See the recording and playback controls in Automator's toolbar? Yes, they do exactly what you'd hope. Click <em>Record</em> and start doing stuff on your Mac. You'll see Automator's <em>Recording </em>notification panel appear (right) which can be used to stop the recording when you're done. Then, you can click <em>Run</em> from the toolbar. Automator will attempt to repeat your steps, including mouse and keyboard input, to automate the same action.

A couple of tips;
<ul>
<li>Keyboard input is more reliable than mouse input, especially when whatever you're trying to automate isn't always in the same screen position. Automator will drag the cursor to the same screen position you recorded no matter where the file or window is on screen next time.</li>
<li>Insert pauses into the workflow using the <em>Wait For User Action</em> action (in <em>Utilities</em>) to give your Mac some time to perform operations if you're finding it can't keep up with your recording. This can be particularly important for when your Mac is under heavy load.</li>
</ul>
<h3>Scheduling Automator Actions</h3>
You can use iCal to launch an Automator app (or any other file) at a set time each day or on any schedule of your choosing. Open iCal and create an event. In <em>Alarm</em>, choose <em>Open File</em>, then click <em>Other</em> from the resulting drop down menu, browsing to your created app and selecting it. At the scheduled time, an alarm notification will appear and your automated action will occur without the need for user input.

Again, a couple of caveats;
<ul>
<li>Make sure you haven't suppressed all alarms in <em>Preferences &gt; Advanced</em> (<em>"Turn Off All Alarms"</em>), or these schedules won't work. If your calendars are synced to your iPhone or iPad and you prefer to receive audible notifications here and suppress them on your Mac (like yours truly) this may annoy.</li>
<li>Be aware of calendar synchronisation. If you use MobileMe, for example, any other Mac which syncs to the same calendar will perform this action at the scheduled time.</li>
</ul>
Now that you've found your feet, head on over to Apple's <a href="http://www.apple.com/downloads/macosx/automator/">Automator downloads page</a> and <a href="http://automatorworld.com/">Automator World</a> to see some examples of what others have created!

Xavier
20th July 2010, 12:52 PM
For iCal, I would make a new calendar for automator processes and not sync the calendar to my other devices. Good article, thanks.