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.

2 comments:

Ed said...

Shouldn't this be a bug for Apple to fix? In the mean time, we have your workaround.


Ed

Deron Dantzler said...

Hopefully you'll find the time to reply. I want to create an automator workflow to utilize "setfile -a V" to hide folders. I'm having a hard time getting this to work properly. The biggest problem that I have is designating the selected finder items to be the folder that the command is ran on.

Can you help?

Creative Commons License

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

Creative Commons Logo