Automator tricks: passing multiple parameters on the command line

The Automator app is the Apple workflow manager that allows automating (what else?) a set of operations on the Mac.  The generated workflow can be invoked from a shell, via the automator command.

Of course, to be really useful a workflow needs to act on parameters, and passing parameters from the shell is easy:

automator -i input_params workflow_name

But what if we want to pass multiple parameters to the automator? We need to separate the parameters with a \n (a newline char).

In the next example, 5 parameters are passed: A B C D E

automator -i "A
E" /Users/ronchet/Dropbox/ImgExtractor/countPars.workflow/

Note the quotes to prevent the new-line to immediately execute the command!

Let us now suppose we want to know how many params were passed, and which is the last one. We could use as first component in our workflow the following shell script:

echo $N
eval last=\$$N
echo $1
echo $2
echo $3
echo $4
echo $5
echo Number of params is $N
echo the last parameters is $last

Note the role of the eval command.

Tagged with:
Posted in Programming

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: