May 17, 2007

Heading down the road with Automator and AppleScript

Lately, I've been working with a large customer to prototype the use of Macs to see if they are a viable alternative to the Windows based platform that they have standardized on in the past. You and I know this to be the case, but they need some convincing. One of the most compelling things for the users at this customer appears to be the use of Automator to automate their individual workflows.

First of all, the users I am dealing with are not programmers, but somehow when they see Automator they immediately get how it could help them get their jobs done. The problem I've had is that a lot of what these folks do involves querying multiple web sites and passing data from the results of one query to the next.

Certainly, any specific workflow could be implemented in code by a developer, but what I really want to do is to figure out a way to provide them with the tools they need to be able to build their own custom workflows.

So, this has gotten me to finally get off my tail and learn AppleScript and Automator. As a developer, it seemed to me that Automator was nothing more than a flashy toy that would be difficult to get any real work done. But perhaps the truth was that I, with years of C, C++, Java, JavaScript, Objective-C, Perl and Python and my programmer's brain, am not the real target audience for this tool. And AppleScript has always seemed to be a very weird language with strange syntax and poor documentation. Heck some of the best programmers I know have stayed away.

Well, necessity is a good teacher, and so lately I have been developing a lot of Automator actions to fill in the gaps I've seen in the built-in actions and third party additions. I've also become interested in how I can use GUI scripting to enable users to more easily help themselves.

Over the next several posts, I'll share some of my actions, talk about finally getting my head around AppleScript, and head down the GUI scripting road. Perhaps some of you will share some of your own experiences too. It would be great to hear from you.

Here are some good links I've found regarding Automator and AppleScript:

Automator:

http://developer.apple.com/macosx/automator.html
http://automator.us
http://automatorworld.com
http://automatoractions.com

AppleScript:

http://applescriptsourcebook.com/
http://developer.apple.com/applescript/
http://macscripter.net/
AppleScript: The Definitive Guide, 2nd Edition

4 comments:

Alex said...

I have taken an opposite path to you, it seems. I am a programmer who started with AppleScript and graduated to Cocoa when I needed more power and flexibility to develop applications.
AppleScript is indeed a strange language when you are used to C-like syntax, but it is a very approachable and, dare I say it, fun way to program. The ability to script a huge number of Mac apps alone makes it worth the investment in time for my job, which revolves around workflow efficiency and automation.
Matt Nueberg's book (The Definitive Guide) is the best resource I have found. He emphasises the trial and error approach to AppleScript, which seems to me the natural way to work with the strange semi-english-like zen of the language.
Having developed a few Objective-C Automator Actions for clients, I can vouch for the usefulness of this often overlooked functionality of Mac OS X.
Anyway, I am very much looking forward to reading about your adventures in Automator and AppleScript as you continue down the road.

Frank said...

I enjoyed your convolution in Quartz tutorial series. I also agree with your comments on AppleScript and Automator as low-effort extensions to Cocoa apps, even ones you didn't write yourself, except for the low effort part. You're probably right about the returns being worth it, but there is quite a learning curve in there.

For example, a while back I wrote some posts about trying to use Automator to scale and pad some images, but the images had to be padded with a specific color. Apple's scale action doesn't support specifying the padding color.

I had a Quartz Composer composition that would do it, so I thought, hey, all I have to do is write an Automator action that wraps any composition with an image input and an image output! Then I noticed Automator doesn't ship with the necessary conversion actions. I downloaded some samples and took a stab at getting those working, but finally decided it was too much trouble and I'd be better off, and learn more, if I just wrote the scale and pad myself in Core Graphics/Core Image, so I did.

I'm looking forward to benefiting from your exploration of AppleScript and Automator because I could see their usefulness in expanding the feature set of my scale and pad app.

Paul Franceus said...

Alex-

I am beginning to enjoy the AppleScript programming at this point. It took me a long time to start getting my head around it. I remember going to a Sal Soghoian talk at WWDC and thinking "hey, this isn't so bad." Unfortunately as I walked out the door the reality distortion field lifted and I was back in the dark. I guess I've banged away at it long enough to open a small crack at this point. At some point in this series I'm planning on delving into more Cocoa based actions but I'm going to start out small.

Frank-

I'm glad you enjoyed the last series. I think that for simple cases AppleScript can be pretty easy - most of my actions at this point have been only a few lines of code. We'll see how well it scales.

I guess you could have written an action that accepted and returned file references instead of image data - maybe that might have worked. Have you thought about writing an action that uses your standalone application to process the images the way you wanted?

It's not clear to me yet how much effort it's worth putting into an action. In my case, one action that is well used could possibly help a large number of folks do their jobs better - so maybe I can spend a few weeks on each.

Thanks for the comments.
Paul

Elavarasan said...

Hi, I'm new to applescripts... I have also seen the automator... So is there anyway that a automator record can be converted into applescripts?

Thanks!!!