Hints & Tips

Hints & Tips

Sanitize Filenames for Shell Scripts

[Joe Block](mailto:jpb@ApesSeekingKnowledge.net) writes: *"I ran into an issue with Automator workflows that call unix shell scripts. I've detailed it [here](http://digitalhominid.blogspot.com/2005/05/automator-and-shell-scripts.html), but it boils down to if you have a workflow that sends filenames to the unix script, you need to add an extra Applescript step to sanitize the file names.*

*Just put a* Run Applescript *action ahead of the* Run Shell Script *action, and put the below code in. It'll take the list of file aliases and convert them to properly quoted paths for the shell script to act on."*

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

Comments

6 Comments »

  1. Excellent! I was going to need this during the next few days for a workflow. Thanks.

    Comment by Peter Dekkers — May 20, 2005 @ 5:13 pm

  2. I just wanted to note that I didn’t write that script – Mike Ashley from the Automator-Users list did

    Comment by Joe Block — May 21, 2005 @ 11:04 am

  3. Yes– I should have pointed that out in the posting.
    By they way, anyone interested in signing up for the Automator (or any other) list, go to http://lists.apple.com/mailman/listinfo

    Comment by Steve — May 21, 2005 @ 11:25 am

  4. No problem, I just wanted to make sure that I gave him credit for his assistance.

    Comment by Joe Block — May 21, 2005 @ 3:42 pm

  5. That’s really cool. Thanks. But come someone tell me how to then use that parameter in the next shell script?

    Comment by Paul — May 22, 2005 @ 10:28 am

  6. If you are creating the shell script yourself, you can always use the quoted form of the path in the script in the script itself. i.e. “$path” (the variable in quotes).

    Comment by jgrafix — November 30, 2007 @ 9:04 pm


Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>