On May 15, 2005, at 5:03 PM, Joe Block wrote:
Here are the details of the workflow I created to process a folder tree and run a unix command on each file in the tree.
Step 1: Get Selected Finder Items
Step 2: Get Folder Contents, with "repeat for each subfolder found" checked
Step 3: Run shell script with "Use input as arguments" checked.
The shell script is a simple ruby script, testit.rb (source follows):
-- cut --
#!/usr/bin/ruby
ARGV.each {|arg| puts arg}
-- cut --
If I open a terminal window and invote testit.rb as
testit.rb /path/to/dir/with/files/with/spaces/in/the/names/*
it correctly prints all the file names, including the ones with spaces in them, one per line.
Once I add it testit.rb to the workflow however, Automator chops up the filenames, and if I have a file named "one two three", the "one", "two" and "three" show up as separate lines of output.
Am I doing something wrong here, or is Automator's handling of filenames broken?
I was able to make this work, but I needed to use an applescript action to quote the filenames. I've attached my workflow as an example, and here is the script.
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
You can't expect the do shell script action to quote the filenames, since in general the do shell script action doesn't know what will be done with the input it's passed. You might argue that if it's passed aliases, it should do the 'quoted form of' in addition to converting to POSIX names. It's still not clear to me that's always right, though.
Mike