Thursday Tech Tip – UI Scripting on Mac OS X
Today I wanted to cover a couple of lesser known and rarely used resources available within Mac OS X. I am going to discuss how to automate user interface scripting tasks and managing automated workflows by leveraging the Automator and AppleScript applications. What are the Automator and AppleScript applications? Well, since you asked:
Automator is an application developed by Apple Inc. for OS X that implements point-and-click (or drag and drop) creation of workflows for automating repetitive tasks into batches for quicker alteration, thus saving time and effort over human intervention to manually change each file separately.
AppleScript is a scripting language created by Apple Inc. and built into Macintosh operating systems and is used to perform Inter-Application Communication (IAC) using AppleEvents. As of late, AppleScript can be leveraged within Automator, so you don’t need to use them separately.
I used to leverage Automator a lot more between 2003 and 2005 but for some reason got away from it. After I recently purchased a new MacBook Pro and set it up as a new machine, I rediscovered the joys of automation with Automator and AppleScript. I also mentioned the benefits of taking the ‘Setup as a New Device‘ approach in a previous post., check it out if you haven’t already. Well, while setting up the new device I noticed I was doing a lot of time-consuming set up tasks that I wish I could automate. That headache led me to rediscover Automator and AppleScript. Now, I am leveraging them more and more in my work for testing and prototyping web services along with personal tasks like file and system management.
The key benefit of using these tools is that not only can you automate routines, but you can extend the existing functionality of other applications on your Mac by saving your automated projects as plugins that can be called within other apps themselves. For example, you could create a plug-in for the mail app that automatically looks for JPEGS or other attachments in your emails and saves them to a specified temp folder so you never accidentally lose important attachments. Or, you could create a location-based service that switches your Mac between work and home modes based on your geo-location. Maybe, you work in video editing or photography, you can create a workflow to automatically perform routine pre-processing work you do like formatting, duplication, and sorting, that would normally take a ton of time. Especially beneficial if working with hundreds or even thousands of files.
Lastly, if you don’t see Automator actions available for a particular application you want to create a workflow for, you can simply drag and drop the icon for that application onto AppleScript or search for, download and use the import tool in Automator. Those steps will allow you to add additional AppleScript and Automator Event/Action libraries from outside sources. Automator itself supports variables, alerts, user input, and many more event based context that allow you to write workflows that can account for the known and unknown details. If you haven’t used Automator and AppleScript before, test out some of the examples out there and start getting more out of your Mac today.