I've got a simple shell script that I would like to incorporate into an automator workflow. I just need to double click the application , pick a finder folder and run the command. At the moment it is running in my default user directory. I've found how to do this as a service, but I'd like it to work as an application. How can I get to run in the chosen folder? Optionally a drag and drop onto the application would be nice as well.

enter image description here


You can simply pass the selected folder to the shell script by selecting "as argument" from the "pass input:" dropdown-menu and then adding "$@" at the point in your script where you want the folder path to be used.

To use drag&drop, just remove the "ask for finder items" action and let the "run shell script" receive the input from "application can receive files and folders as input".

  • I've seen the "$@" command but wasn't sure how to use it. I simply put "cd $@" at the beginning of my script and it solved the problem. Thanks for your help. – Corey Riggle Mar 1 '11 at 21:27
  • Actually, I'd recommend using cd "$1" instead. $@ expands to the list of all arguments passed to the script, and if there's more than one cd will just gripe that it can't go more than one place; $1 expands to the first argument, so if you manage to pass it more than one it'll just go with the first. Also, make sure you use double-quotes around it, to keep the shell from getting confused by funny characters (like spaces) in the folder path. – Gordon Davisson May 7 '11 at 15:42
  • @Gordon In this case, with the "Allow Multiple Selection" checkbox unchecked, there will actually never be more than one argument passed to the shell script. Putting $@ in double quotes is indeed necessary (as I did in my original answer). – Asmus May 10 '11 at 10:44

The way I do this is define the path to a variable, then open up the workflow in a text editor, search for the variable, copy the string, then use $(string) anywhere in the workflow whatsoever (including shell scripts).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .