Automator is a little used, and misunderstood application available to all Mac users. If you’ve used it before, then you might find this article interesting as it looks at setting up an automatic folder action for your workflow. If the previous sentence didn’t even make sense, then read on to find out what Automator could do for you. 🙂
OSX, like Windows, has a scripting utility built into the OS that allows you to automate common tasks. On the Mac that tool is AppleScript, and you can use it to instruct the OS or certain applications to carry out tasks. Not all applications can be directly controlled by AppleScript – but some of the most useful ones can be. In this post I’ll show you how to create a basic workflow to scale an image file down to a suitable size for uploading to a WordPress blog, and then convert that image to a PNG file. I’ll then attach that workflow to a specific folder, so that any files that are dropped into that folder are automatically converted by the workflow we setup.
The first hurdle is to learn how to write AppleScript. Luckily Apple have thought about this, and have created a tool that saves you having to write ANY code whatsoever. That tool is an app that ships with OSX called Automator. Search for it using Spotlight – or look for it in your Applications folder – and when it launches you’ll see this interface:
We’re going to create a workflow for files in a particular folder, so select the ‘Folder Action’ template and press ‘Choose’.
Now you’ll see the automator interface where we can begin to build our workflow of actions. There a a large number of scripts, referred to as ‘Actions’, already defined in the Library. If you know what you’re looking for, you can just search using the text box at the top. Or you can select the various categories of scripts depending on the kind of workflow you want to build.
For this example I need to have any image I’ve dropped into a specific folder resized to a certain resolution, and then converted to a PNG file. So the first script I need is one that will scale or resize the image. Click on the ‘Photos’ category, and you’ll see a ‘Scale Images’ script. Just drag it across into the workflow area on the right. You may see this warning pop up when you do:
This warning is important! What Automator is telling us is that if we don’t do anything at this point, these scripts or actions will be performed directly on the files we drop in the folder. In other words, the original files will be changed and overwritten. In this example, that’s ok. I want the workflow to operate like a dropbox. But in other workflows this will probably not be a good idea. If you click Add, it will add a ‘Copy Finder Items’ action which allows you to select a location to create copies of the files that this workflow produces. For now, click ‘Dont Add’, and continue.
Next we need to add an action that will convert the images to PNG files. This action is sometimes a little tricky to find as it’s named ‘Change Type of Images’. Look or search for it, and drag it into the workflow below the ‘Scale Images’ action.
Now that we have the two actions we need to complete our workflow, make sure the paramaters are set correctly. For this example, I know I want to scale the images to ‘1024’ pixels, which will make sure the longest side of any image is scaled to this size. The image type needs setting to ‘PNG’ in this case.
Because we chose to attach this workflow to a folder, the top of the workflow pane asks us to select the desired folder:
I simply created a folder in my Pictures folder called ‘Converted images for blog’.
Now simply select ‘Save’ from the File menu. Because this is a folder action, it wont ask you where to save the workflow – but simply ask you for a name for the action. I simply named it ‘Convert and overwrite images for WordPress blog’.
… and that’s it. You can quit Automator now, and try out your new folder action. Just drop an image file into the folder you created, and within a few seconds later you should see the image automatically resized, and converted to the PNG format. It’s that easy!
If you need to manage your folder actions, simply CMD-Click on the folder in question, and choose ‘Folder Actions Setup…’. Here you can see what actions are already in use, and even select from some common built-in folder actions. You can also select an action to edit from this window, so if the workflow needs tweaking that’s easy too!
This is just the beginning, of course. Automator gives you a very quick and easy way to build workflows to process files. You can attach them to folders, as we have done in this example – but you can also run the scripts directly from within Automator, which is handy for one-off batch conversions. You can also create standalone applications from your workflows, which you can use to drop any file onto to begin processing.
Take the time to explore what Automator can do for you. The number of features available increases if you have compatible applications installed – and there are plenty of free and commercial actions you can download from Apple’s Automator website. Automator workflows can be as simple or as complex are you like, and if you want to take the next step you can even insert AppleScript code directly into your workflow.
If you ever find yourself repeatedly doing some common task on your Mac, take a few minutes out of your day and see if Automator can help you work that little bit smarter. Automator’s workflows are completely portable, so anything that works for you can easily be shared with your team or friends.
Go automate yourself! 😀