In Automator, each task is called an action, and you can link multiple actions together to form a workflow.. Chapter 2: Automator Overview Action Input/Output Values In an Automator wor
Trang 1Chapter 1:
Introduction
What You Need to Get Started
For the first section of this book, you won’t need much
to get started, other than a basic familiarity with Mac
OS X and a copy of Mac OS X 10.4 or higher Since Automator interacts with existing applications on your machine, you should also be comfortable using at least the core applications that are installed with Mac OS X, such as iTunes, iPhoto, Mail, and Address Book
The second section of this book focuses on development and assumes that you have at least some prior experience developing software for the Mac OS
X platform You should have some familiarity with Xcode and Interface Builder, Apple’s free software development tools You should also have a basic knowledge of AppleScript and Objective-C
Brief introductions to both of these languages will be provided at the beginning of the developer section
of the book However, you may wish to consult more in-depth resources as well Sal Soghoian
and Bill Cheeseman's AppleScript 1-2-3 (Peachpit Press) serves as an excellent training guide for any developer interested in learning AppleScript For an introduction to programming, check out Stephen G
Kochan's excellent Programming in Objective-C (Sams Publishing)
Software Utilized in this Book
The following specific software versions were used during the creation of this book:
4 Mac OS X version 10.4
4 Automator version 1.0
4 Interface Builder version 2.5 (for developers)
4 Xcode version 2.0 (for developers)
If you are using older versions of this software, please
be aware that some or all of the functionality discussed may not be available to you If you are using newer versions of this software, then you should be aware that certain aspects of the software might differ slightly between versions Regardless of the software versions you are using, it is always recommended to conduct testing of any sample code prior to usage, as minor adjustments may be required, due to changes in terminology between versions
In addition to the specific software listed above, the examples in this book will make use of various Apple applications in order to construct Automator workflows If your system software is up to date, then you probably won’t need to be concerned about the specific versions of these applications, although there could possibly be differences in behavior between versions
Trang 2Chapter 1:
Introduction
Example Code
All of the examples and sample code included in this
book can be found in a directory named Automator Examples, which is included in your purchased eBook
download Nested inside of this directory are sub-directories, named for the chapter to which the example files apply Please note that not all chapters will have
example files in the Automator Examples collection.
Move the Automator Examples directory to a
convenient location on your hard disk, from which you can view and edit the files
What’s Next
The next chapter begins the first section of the book, and is geared primarily toward users We will begin discussing the Automator application itself in greater detail, and discuss its features and benefits We will also look at some examples of the types of workflows that can be made more efficient with the use of Automator If you are a developer, you may still want to review the chapters in this section in order to become familiar with the Automator application
Trang 3Section 1
13
Using Automator
Trang 4Chapter 2 Automator Overview
14
utomator’s purpose is simple – to automate the time consuming, repetitive, manual tasks that plague our lives on a daily basis Automator is easy to configure and highly customizable With Automator, there’s no need to wait for your favorite applications to implement macros or other scripting devices, and there is no need for custom programming Automator gives you
complete control over your workflow and puts you in
the driver’s seat
Automator is installed in the Applications folder
with Mac OS X, versions10.4 and higher It is easily distinguishable by its icon, which, appropriately enough, looks like a robot See figure 2.1
Figure 2.1 The Automator Icon
Benefits of Automator
As with any type of automation, there are a number of benefits that come from using Automator A primary benefit of Automator is that its user-friendly interface makes automation simple for the average user The
key here is average user With Automator, it doesn’t
take a rocket scientist to build an automated workflow
By putting such an easy-to-use tool directly into the hands of the average user, Apple ensures that virtually
everyone is capable of implementing automation into
their daily routines
Automation can actually reduce stress That’s right, you read that correctly Automation reduces stress By removing the same old repetitive, boring tasks from your workload, you will feel a renewed sense of energy and motivation, as you will become free to focus on things that you actually enjoy, like graphic design, photography, and more
Another benefit of automation is a reduction in user errors No matter what we might like to think, we all
do make mistakes from time to time On the computer, these mistakes are often as simple as entering an
Trang 5Chapter 2:
Automator
Overview
incorrect file name, accidentally deleting something, moving something into the wrong folder, etc However,
by automating manual tasks, you can eliminate the possibility of user errors occurring when those tasks are performed A properly configured automated workflow will not make mistakes It will perform consistently and accurately day in and day out, like a robot
In addition, since an automated process can interact directly with the computer, it eliminates the time that would have been necessary during manual processing for things like moving and clicking the mouse, pressing keys on the keyboard, mulling over what to do next
The result is a much faster workflow, which can allow you to accomplish a lot more in the same amount of time, or possibly in even less time Depending on how automation is implemented, it may even be possible for your processes to run unattended, allowing you to trigger it while you are at lunch, or when you leave your computer at the end of the day
Increased accuracy, efficiency, and quality are all some
of the benefits of automation As you begin to use Automator, you will encounter these benefits first hand, and, once you do, you will wonder how you ever functioned without Automator
How Does Automator Work?
Automator works by interacting with existing files, folders, and applications on your computer, or by interacting with the operating system itself When using Automator, you first select the applications or types of processes that you want to automate, and then you specify the tasks that you want to perform within those applications or processes
In Automator, each task is called an action, and you can link multiple actions together to form a workflow The workflow you create may then be triggered from within Automator, or it may be saved and triggered outside of Automator in a number of ways Once triggered, the actions within the workflow will process sequentially
Automator Actions
Most Automator actions are designed to perform
a single specific task, such as writing text to a file, opening a URL, or copying files from one location
to another Because of this, actions may be linked together sequentially to form a larger, multi-part, automated process
When you begin planning an automated workflow, think of the tasks that you would normally need
to perform manually You might step through the sequence manually, and outline each step as you go Think of each of these steps as a single Automator action When you build your workflow in Automator, you will assemble these actions together to form a complete workflow
Trang 6Chapter 2:
Automator
Overview
Action Input/Output Values
In an Automator workflow, each action has the ability to pass information along to the next action
in the sequence Likewise, actions can also receive information from the previous action in the sequence
For example, you may build a workflow that retrieves
a list of files from a folder, compresses the files into
an archive, and attaches the archive to a new email message A workflow of this nature might consist of three separate Automator actions (see Figure 2.2)
4 The first action retrieves a list of files within a specified folder, then passes that list on to the next action
Figure 2.2 Automator Action Interaction
4 The second action takes a list of files as input, then compresses the files into a single archive The location of the compressed archive is output to the next action
4 The third and final action would tell Mail to create
a new email message and attach the archive, which was received as input from the second action, to that message
Information passed between actions can take on a variety of forms Some actions may pass file and folder paths to the next action, some may pass text, some may pass email messages The type of information input
or output by an action will depend on the task that the
Trang 7Chapter 2:
Automator
Overview
action is performing
Since many actions are designed to process the information that is passed to them by the previous action, when you link actions together to form a workflow, you will need to make sure that each action passes the appropriate type of information to the next action in the sequence For example, an action that will compress files into an archive will only be able to accept file paths from the previous action in the workflow sequence Passing the wrong type of information to the action would produce an error We will discuss this further when we begin building a workflow
An action might take one type of information as input,
and output a different type For example, the Download URLs action, included with Automator, will accept a list
of URLs from a previous action as its input, and output the file paths of the downloaded files to the next action
in the sequence Some actions may be configured to
serve as conversion actions, whose purpose is only to
convert information from one type to another, to be processed by the next action in the sequence Other actions will perform a task, and then simply pass the output of the previous action through to the next action
in the workflow sequence
In some cases, actions may also be configured to ignore the output of the previous action in a workflow This
is sometimes necessary, as we will see when we begin constructing workflows
Action Settings
As we will discuss in detail in a future chapter, when you build a workflow, you will also specify settings for many of the actions in a workflow The settings that you specify will control how the action behaves when it
is triggered in the workflow
For example, using the scenario we discussed earlier for sending compressed files in an email, the compression action in the workflow would need to be configured to know where to save the compressed files This action might be configured to save the compressed files to
a specific folder, such as the Desktop, every time the workflow is run
In some cases, you may not want to specify the settings for an action when you configure the workflow
Instead, you may want to give more control to the user, and allow the user to specify the settings when the workflow is triggered Many actions offer this ability, and can be configured to display settings to the user during processing For example, using the compression example again, you could configure the action to
prompt the user to specify the output folder for the compressed files each time the action is triggered Some actions that will perform a single, very basic task may not require settings to be specified at all For example, Automator includes an iTunes action for updating a connected iPod This action does not require any settings to be specified It will simply update any connected iPod, using iTunes
Trang 8Chapter 2:
Automator
Overview
Application Interaction
The applications with which Automator can interact depend entirely on the actions you have installed on your computer Fortunately, Apple includes hundreds
of actions to get you started The actions that are installed with Mac OS X cover most of the core Apple applications, including Address Book, the Finder, iPhoto, iTunes, Mail, and Safari, among others Apple also provides actions for interacting directly with the operating system and files on the system
It’s probably fairly safe to assume that you also use applications other than the ones Apple provides to you
If you do, then you’re not out of luck either Third-party Automator actions for a variety of applications are available from a number of developers Since Automator is still new (at least at the time this book was written), the list of third-party actions may be small at the onset However, the number of third-party actions
is sure to grow quickly For a comprehensive up to date list of third-party Automator actions, visit Apple’s Mac OS X download website at
http://www.apple.com/downloads/macosx/, or check out http://www.automatoractions.com
Limitations of Automator
Like most applications, Automator does have some limitations, which are worth covering
First, there is a possibility that, in some cases, actions cannot be developed for certain applications If you encounter this situation, it is because the developer of the application has not provided the necessary “hooks,”
allowing developers to create actions that interact with that particular application
If you learn of an application that does not support Automator action interaction, contact the application’s developer to suggest that such support be
implemented A developer can implement Automator action support in two main ways The developer can make the application AppleScriptable, which can allow for even greater automation possibilities, or the developer can implement a public API (Application Program Interface, a way for programmers to hook into
a third-part application).
Another limitation of Automator is that, while it can
be used to automate a large number of tasks, it cannot
be used to create really complex automated processes When you configure an Automator workflow to trigger specific actions, those actions will execute in the exact order that they have been configured, one right after the other A workflow cannot include any logic to take
a different course of action if a certain situation occurs during processing
In addition, because actions in a workflow trigger
in sequence, each action can only receive as input the output of the previous action An action has no knowledge of the output values of other actions in the workflow This can put some limitations on the ability
to pass information around throughout the workflow Because of this, you probably wouldn’t use Automator
to do something extremely complex, such as building
Trang 9Chapter 2:
Automator
Overview
a two thousand page catalog of products for your company in QuarkXPress, using data from FileMaker Pro In order to achieve complex automation like this, you would probably want to use something like AppleScript instead AppleScript powers much of the behind-the-scenes functionality of Automator, and is a more appropriate fit for more complex automation
An AppleScript can be written to perform just about any task imaginable on the Mac, and can include all the logic your unique scenario could possibly require
Though relatively simple to learn in comparison to other languages, AppleScript does have a much larger learning curve than that of Automator
To learn more about AppleScript, check out Sal
Soghoian and Bill Cheeseman’s AppleScript 1-2-3
(Peachpit Press)
What’s Next
Now that we have learned a little bit about how Automator works, it is time to get started actually using
it In the next chapter, we will explore various aspects
of Automator’s interface Once you understand the interface, we can begin to implement some example workflows, helping you to take advantage of this awesome technology
Trang 10Section 2
87
Developing for Automator