Building an Automator Action

In the interest of working more with GeoBloggers and Flickr - as well as my own interests in geolocation, I'm writing some Automator actions. You gotta pay the toll to the bot.

I'm trying to create a photograph workflow that will archive images, apply EXIF copyright as well as geographic location, and then archive.

The tough part, obviously, is the geographic location. The rest was already all done by many small gnomes at 1 infinite loop. I've already written an GeoExif Applescript that a user would select images in iPhoto, run this applescript, and then fill in the location information piece by piece. Tedious, no?

Anyways, building automator workflows is *incredibly* easy (well, except for sometimes getting the actions between other actions. sometimes the current actions just are little *too* friendly and all huggly and whatnot and then this "View Results" action's gotta be like 'hey, I wanna piece of this text').

Just add the "Run Applescript" action to your workflow. A small, but illustrative example of what the applescript looks like for an automator action:

on run {input_items, parameters}
if input_items is not {} then
set myPrefix to "prefix_"
repeat with item in input_items
set (name of item) to myPrefix & (name of item)
end repeat
end if
return input_items
end run

To dissect: first we declare we want the input_items which are the magically river of data coming into and out of the connectors in automator actions. What type this input_items is automagically determined for you by the Applescript automator action. If you were writing your own action in XCode2 you would need to specify the acceptable types in your InfoPList.strings file.

So, first we see if this input_items has anything in it. If not (e.g. you didn't connect the input in Automator) then the array is empty and our else block gets run. If you *have* connected the input, then the array isn't empty and we start doing stuff with the input.

You may want to setup some stuff before the loop (such as setting a prefix variable), after which you just do repeat with item in input_items to begin recursing through all of the incoming objects. You can access the parameters of the object and whatnot to your heart's desire.

When you're done playing with the objects, just return them, or some semblence of your results, out to. This will get passed onto other actions.

Yay! you've written an automator action, yay!

About this article

written on
posted in ProgrammingApple Back to Top

About the Author

Andrew Turner is an advocate of open standards and open data. He is actively involved in many organizations developing and supporting open standards, including OpenStreetMap, Open Geospatial Consortium, Open Web Foundation, OSGeo, and the World Wide Web Consortium. He co-founded CrisisCommons, a community of volunteers that, in coordination with government agencies and disaster response groups, build technology tools to help people in need during and after a crisis such as an earthquake, tsunami, tornado, hurricane, flood, or wildfire.