As avid computer users we all know how many tedious tasks we have to deal with on a daily basis. However, we tend to ignore an important fact: we’re using a computer. We shouldn’t do any of these tasks by hand. Everything that sounds repeatative should be accomplished by a computer, not by hand. Let’s see how we can achieve this on a Mac Utilizing Automator.
Automator is a utility hidden in every Mac. If you’re a web designer needing more and more time to accomplish your tasks, you should begin to use it now. Automator lets you perform a series of actions on your Mac which can save you a great deal of time.
Automator Workflows
When you create a new workflow in Automator, it will ask you which type of workflow you want to create. The standard workflow is a workflow that can be run inside automator. It’s useful for testing purposes, but you should convert it to something more usable when you’re ready to run it. The application workflow is very interesting because it will convert your workflow to a standalone application.
You’ll be enabled to run it outside Automator, like a normal application. It also supports drag and drop, so if you drag an element on the application icon it will be treated as the application’s input. The service workflow will let you run your workflow using a menu item accessible in the services menu.
This means that you can run it in every external application. The print plugin, ical alarm and image capture plugin are pretty self explanatory and are outside the scope of this article.
Our focus in this case will be on the Folder Action Workflow. Why this is so important? Well, it’s really simple and powerful. You create a folder, assign your workflow to that folder and that folder will be always monitored. Every time you drag an item in that folder, the workflow will be launched. Let’s take a look at our first workflow example to understand how it works:
Simple Unzip Workflow
Let’s start by creating a folder on our desktop and name it Unzip. Then we’re going to create our first workflow in Automator, as a folder action. On the left side we have all our actions and on the right we have our empty workflow. The first thing to do is telling our workflow to which folder it should be connected. Select the Unzip folder from the drop down menu on the top of the workflow view.
Now the workflow is linked to our folder. Let’s describe the scope of our first folder’s action. We want to create an action that unzips an archive and deletes the original zip file. How many times we do this by hand every day? This action will save us a lot of time. The first action that we have to drag in the workflow is “Filter Finder Items”. This is necessary because we want to target only zip files in our directory.
So we can create a rule that checks if the file extension contains zip. Now that we filtered items in the folder we can unzip the archive. We can use the action “Open Finder Items” and the zip file will be automatically opened with the OSX unarchiver.
Now we have the original zip file and the contents of the zip file in our folder. We can delete the original zip file by “Get Folder Contents” targeting zip files and “Move Finder Items to Trash”. To test the workflow just drag a zip file in the Unzip folder. It will be extracted and deleted.
Rename by Pattern
This is another common tasks that we repeat every day. We download a file from the Internet and we have to rename it. We can create an automator workflow to understand the pattern used in the filename and rename it following our personal pattern.
In this case we’ll need a really useful automator action, “Rename Finder Items by Pattern”, that can be downloaded for free. Let’s create a new folder named Rename and add a new folder action linked to this folder.
The first action that we have to use is “Get Folder Contents”, which will retrieve all the elements in the folder. Now we can add the “Rename Finder Items by Pattern” previously downloaded. This action works using pattern matching. In this case we have files that are named filename-otherstuffs.txt. We want to rename our files just using the filename part and removing the dash and the words after the dash.
The action that we’re using takes a pattern as input. In this case we have to use the *-* pattern. This means that we’ll have a different variable for every asterisk. Variables are named $1, $2, etc. In this case we’ll have a $1 variable that will be “filename” and a $2 variable that will be “otherstuffs”. So in the field “Replace With” we can just use $1. Every file having this pattern that we’ll drag in the folder will be renamed to filename.txt.
Image Size and Save for Web
This is the most important action for a web designer. We receive images from a client, we have to resize them and save for web. Then we’ll be able to use these images in our web project.
Let’s do it automatically. First of all, let’s download a great actions collection. In this collection there’s a great “Save for web” action that will be perfect for our workflow. Let’s start by filtering finder items in our folder, selecting only jpg images. We have to add another important rule to our filtering action: select images that have not been already resized.
This is important because if we don’t add it, our workflow will run in a loop, resizing the image infinitely. Now we can add the “Save for web” action previously downloaded.
You can see in the picture how we configured it. It’s really simple, but the important thing in our case is to “Delete original files”, to prevent looping. The we have to add the action “Add text to finder item names” using the _resized suffix. When you drag an image in the folder, the image will be resized to 800 pixels, saved for web and renamed with a _resized suffix.
Conclusion
As you can see, it’s very simple to create and use Automator workflows to save time. The previous examples show you all the basic knowledge to create your own workflow as a folder action. There’s just one important thing you need to know before working in Automator: it doesn’t have an undo function.
Therefore if you create an automator action that moves all your hard disk to trash and you click run, you can’t go back. This is virtually the only drawback of this wonderful utility. Always make sure you test your workflows inside a sandbox folder and on dummy files. When you’re absolutely sure that everything is functioning as needed, you can then use it in the finder.