Thursday Tech Tip – UI Scripting on Mac OS X

7 Nov , 2013 Technology

Thursday Tech Tip – UI Scripting on Mac OS X

Automator_Icon

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_Icon

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.

Automator_UI

The possibilities are really endless. I created a an example Automator workflow that I posted on GitHub for getting data from a rest API, doing something with the file and then passing it on to another site or service. Just one example of how you can use Mac OS X automation tools for automating larger projects. Moreover, Automator has some cool additional tricks up its sleeves for making it even more powerful. For one, Automator can run Shell, Xcode and JavaScript within workflows; so you can use your coding skills to perform more complex system level or app specific tasks.

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.

, , , , , , , , ,


Leave a Reply