Automator: Running a Workflow on Folder Contents

In yesterday's post (Automator: Scheduling Workflows to Run Automatically), we walked through how to create a multi-action workflow and then schedule that workflow to run automatically in Calendar as a recurring event. In today's post, we'll walk through how to create a workflow that runs when files are copied or moved into a specific folder (with the folder acting as the trigger).

To illustrate this, we'll create a special folder that resizes images when they are copied into the folder. We'll also keep a copy of the original file in the folder so that we can refer to the original size if we need to. When we're done, you will have a folder-based workflow that will leave your original image in tact, as well as give you a copy of that image (or multiple images) at a lower resolution, great for sharing via email or photo-sharing sites.

Let's get started!

First, we need to create a new folder. I created one on my Desktop called "Image Resize". You can call yours whatever makes sense to you.

Next, we need to create a new Automator document. Rather than creating a "Workflow" document, we're going to dive straight in and create a new "Folder Action" document.

One thing you will notice that's different between a "Workflow" document and a "Folder Action" document is the option at the top of the canvas window to attach this workflow to a specific folder.

Before we start building our workflow, let's go ahead and assign this new document to the folder that we just created on our Desktop. Once you have located that folder, we can begin building our workflow.

To keep this example relatively simple, we're only going to use two actions:

  1. Finder: Copy Finder Items
  2. Finder: Scale Images

Rather than adding both actions individually (which is certainly a viable option), we're only going to add the second action ("Scale Images"). The reason for this is simple: Automator is considerate enough to warn us about the changes that will happen when it resizes the images. As a result, it will automatically ask us if we want to make a copy of the original images first.

When we see this prompt, we will choose to add the copy action. Automator will add this copy action before the resize action (remember, the flow of actions is very important) so that it runs before any modifications are made to our image files.

At this point, we can now review both actions and make any adjustments necessary. After making adjustments, my workflow looks like this:

When I save my workflow and move or copy a single image file (or multiple image files) into the folder, two things will happen:

  • The folder will contain the original images
  • My Desktop will have a copy of the image files at a lower resolution (300 pixels wide)

At this point, we can save the workflow and Quit Automator. Now it's time to test it! I will drag a series of images from my Desktop into my new folder. Let's see if it works:

As expected, it works like a charm! I have my original files saved inside my new folder, while the new lower-resolution files are now located on my Desktop (as you can see from my previews).

Keep in mind that I kept the actual workflow in this example simple so that we could focus on how to attach a workflow to a folder. When it comes to designing your folder-based workflow, you can add as many actions or steps as necessary to accomplish your requirements.

Editing the workflow (to add, remove or modify actions) is simple. Right-click on your folder, and choose "Folder Actions Setup..." Click "Cancel" on the pop-up window, and you will see a list of folders (system-wide) that have a workflow attached to it. In our example, I just have one folder ("Image Resize") with a workflow attached to it. I will highlight that to reveal our attached workflow. Simply select the workflow and choose "Edit" below to open the workflow within Automator for editing.

Congratulations!! You have just created a workflow and attached it to a folder.

Posted on January 23, 2014 and filed under Design, How To, Mac.