Thursday, 14 April 2016

Automate Repetitive Tasks on Mac


For all the old jokes about one-button mice and simplicity, Macs have some power-user features Windows just doesn’t offer. Automator is one of them, offering a simple way to automate repetitive tasks without any third-party software.

Automator is a powerful tool, and there’s a lot you can do with it. You can use the graphical interface to create automation “recipes” with drag-and-drop, or write AppleScript by hand. A quick web search will lead you to many different examples of things you can do with it.


Launching Automator and Creating a Document

Automator is installed on your Mac by default, so you can launch it by pressing Command+Space to open Spotlight search, typing Automator, and pressing Enter. You could also find it under Other > Automator in Launchpad or Applications > Automator in the Finder.

You’ll see a variety of different document types you can start with. All of these are basically different types of workflows; they’re just triggered in different ways:

  • Workflow: A workflow is a series of actions that runs inside of Automator.
  • Application: An application is the same as a workflow, but it can be run as an application from outside Automator. For example, you could drag-and-drop files onto the application’s icon to run the workflow on it from outside automator.
  • Service: This allows you to create a “service,” which will be accessible from the Services menu in other applications.
  • Print Plugin: A print plugin appears in the system’s print dialog.
  • Folder Action: This is a workflow that you tie to a specific folder on your Mac. When you add files to that folder, your Mac will automatically run the workflow on them.
  • Calendar Alarm: This runs when a specific event occurs in your calendar.
  • Image Capture Plugin: This appears as an option in the Image Capture utility, used when transferring photos to your Mac.
  • Dictation Command: This runs when triggered by a voice command, known as a dictation command, on your Mac.



Creating a Simple Service

As an example, we’ll create a service you can use in any application. First, we’d select Service in the dialog and click Choose. At the top of the window, we can then choose what we want the service to work with. By default, it’s set to “Service receives selected text in any application.” 
This means you can select text and then click the application’s menu, point to Services, and choose your service in any application. (You may also be able to right-click or Control-click the text, depending on the application.)

You could modify this, though. For example, you could choose “Service receives files or folders in Finder” and the service would only appear when you select files or folders in the Finder app.


You can then select actions from the left pane. Drag and drop them to the right side and they’ll be run in the order you choose. For example, we can drag and drop the Text>Speak Text action onto the right pane and choose a voice.


Click the File menu, click Save, and enter a name for your service. It’ll then appear as an option on your system. For example, after saving the above service, we can now select text in any application, click the Services menu, and select our service to have the computer read that text aloud for us.




More Tricks

We created a service in the above example, but the process is similar for any type of workflow you might want to create. You can add multiple actions from the left pane and arrange them in the order you like via drag-and-drop to perform many operations on the items in order. For example, you could create a Folder action that takes images you add to a certain folder, creates a backup copy, and then shrinks them down for you.


You can also click the Record button to record a series of mouse clicks and typing events on your computer, allowing you to automatically perform them later. This is basically like recording a macro, and it allows you to have your Mac copy your actions automatically. After recording, the sequence of events will appear as a “Watch Me Do” action you can place anywhere you like in a workflow.


To do even more, there’s the Run AppleScript action that you can use to automatically run code written in AppleScript. If you search the web, you’ll find a variety of useful actions written in AppleScript that you can copy-and-paste into the Run AppleScript action. This allows you to do more advanced things that don’t appear as easy drag-and-drop actions in Automator.


We’re obviously just scratching the surface here, and that’s the idea. Entire books could be been written on this subject. With the basics figured out, you can poke around Automator and figure out how to make it do what you want it to do. You can also feel empowered to search the web for useful Automator workflows and snippets of AppleScript that can quickly perform those repetitive tasks for you, understanding how Automator works and how to use them.

No comments:

Post a Comment