2005-05-17

Automator and shell scripts

So I was writing my first Automator workflow, and found a bug in the "Do shell script" action. I was trying to write a workflow to iterate over the selection in the finder (and any files in subfolders of the selected files) and use SetFile to change the type and creator. This seemed easy enough, except that it turns out when Automator converts a list of files to strings to hand off to the shell script action, it doesn't properly quote them.

Thanks to Mike Ashley from the Automator-users mailing list for the following code snippet that works around this:



on run {input, parameters}
set output to {}
repeat with i from 1 to length of input
set x to item i of input
set output to output & {quoted form of POSIX path of x}
end repeat
return output
end run



Just put a "do applescript" stage ahead of the "do shell script" stage, and put the above code in. It'll take the list of file aliases and convert them to properly quoted paths for the shell script to act on.

No comments:

Creative Commons License

This work is licensed under a Creative Commons License.
Copyright 2007-2010, Joseph P. Block, Some Rights Reserved.

Creative Commons Logo