6

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

2 Answers 2

8

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".

3
  • 1
    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. Commented Mar 1, 2011 at 21:27
  • 1
    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. Commented May 7, 2011 at 15:42
  • 1
    @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
    Commented May 10, 2011 at 10:44
-1

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 .