Automator for Mac OS X: Tutorial and Examples

Learn how to use Automator for Mac OS X to automate tedious workflows in this tutorial with five complete examples. By Neil North.

Leave a rating/review
Save for later
Share
You are currently viewing page 3 of 5 of this article. Click here to view the first page.

Using Automator Variables

Have a look at your variables tab, and you’ll see a bunch of standard information which can be collected from the system: date and time, system information, random numbers etc. You can drag each of these onto the workflow so its value is accessed via the output.
Screen Shot 2013-12-12 at 6.42.43 pm

Next, you’re going use a variable to store filename of the original image passed into the workflow, so that you preserve the original file.

Back in Automator in your current folder action project, add the Set Value of Variable action to your workflow at the top above Copy Finder Items.

Click New Variable… from the dropdown list and name it Original Input. Your workflow should now look like this:

Screen Shot 2013-12-12 at 6.50.28 pm

Now that the original filename is stored in a variable, you need to retrieve it from the variable after finishing with the @2x version.

Find Get Value of Variable from the actions list, drag it onto the bottom of your workflow, and make sure the Variable selected is Original Input.

All actions on the workflow return an output. The output of the “Rename Finder Items” step is the array of renamed files. However, in this case you don’t care about those filenames and just want to work with the array of files you squirreled away in the Original Input variable earlier.

To fix this, you can disconnect an action from previous outputs. Simply expand the Options of the Get Value of Variable and select Ignore this action’s input. When you make this change you’ll notice that it’s no longer connected to the output of the above action.

Screen Shot 2013-12-12 at 6.57.24 pm

Now you can finish this up by adding another Copy Finder Items action under the Get Value of Variable action and setting it to your Processed folder.

Then add a Scale Images action to your workflow, set it to scale by percentage and adjust the value to 50%.

Screen Shot 2013-12-12 at 6.59.26 pm

Go to File, select Save. You’re done – let’s try this out!

Find some images you can try out (such as that LOLcat image from earlier) and drag and drop them into the Prepare Images for iOS folder.

In your Prepare Images for iOS folder you can see the file(s) you dragged in:

Screen Shot 2014-01-24 at 11.03.45 AM

Have a look in your Processed @2x folder you’ll find the same images, but renamed with @2x – indicating the kitty is ready for retina. Meow.

Screen Shot 2014-01-24 at 11.04.29 AM

In your Processed folder, file names are unchanged. If you look at the dimensions you’ll find they are half the original dimensions:

Screen Shot 2014-01-24 at 11.04.33 AM

Well done! You now have full control over your image assets. Besides working with Retina, you can use this same process to prep images for iPad, iPhone and iWhatever. To do this, all you need is the ration or change for each device, and a single high resolution image.

Beyond that, you can even automate actions for photo manipulation. For example, you can add filters, like posterize and vignette. If you’re working on an image-rich project, look into using Automator – it’ll probably save time and sanity!

Perform SQL queries on an SQLite file using Automator

If you need to use a database within your app, the most likely format is SQLite. It’s light and compact, and is commonly used by Core Data. When you’re developing cross-platform apps, SQLite works great on Android. Using Automator can make managing the database more efficient.

Normally, you’d probably need buy an app to do tasks like set up sample data in your SQLite file, run a query to get data out of your SQLite database, or perform table maintenance. But not after you learn to use Automator, which can make performing SQL functions and queries on your SQLite databases easy!

To start, you’ll make a simple workflow which will allow you to run any queries you want on a selected database.

Note: If your library doesn’t have a Developer Tools category, it’s likely you don’t have Xcode installed on your Mac. Please install Xcode before you proceed with this part of the tutorial, as it uses Developer Tools.

In Automator, select File from the menu bar and then New. This time, select Workflow as the type, as you’ll only be running it from Automator.

Screen Shot 2014-01-24 at 11.19.02 AM

Since there is no file passed into the workflow at the beginning, you’ll have to get the file. In this example, you’ll be using the DataStore file from a Core Data project. Note that one is included in the sample files for this tutorial.

Note: If you would like to view your own Core Data database file, one easy way to get it is to enable Application supports iTunes file sharing in your apps Info.plist file. Run the app on your device and you should then see your DataStore.sqlite file from your iTunes fileshare. Save it to your desktop and you’re ready to go.

Drag the Get Specified Finder Items action onto your workflow, select Add and find the DataStore.sqlite file.

Screen Shot 2013-12-13 at 8.14.55 am

Now that you have the file in your workflow, you can start working with it.

Drag a Execute SQL action onto your workflow. This can run any SQL you want on the database.

Note: If you’re unfamiliar with SQL (Structured Query Language) and plan on using SQLite files a lot, then I would recommend trying w3schools SQL tutorial and our .

Note: If you’re unfamiliar with SQL (Structured Query Language) and plan on using SQLite files a lot, then I would recommend trying w3schools SQL tutorial and our .

In the SQL commands section, you can run as many SQL commands as you want, separated with ;. For now though, you’ll run a query which will work on any Core Data database.

<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> Z_PRIMARYKEY;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> Z_PRIMARYKEY;

When this action runs, its output will be the result of the query. In this case it should contain one line for each entity model you’ve set up.

Now what you need is to be able to see the results returned by the query.

Neil North

Contributors

Neil North

Author

Over 300 content creators. Join our team.