Re: Workflow to run shell script on contents of a Finder selection
Re: Workflow to run shell script on contents of a Finder selection
- Subject: Re: Workflow to run shell script on contents of a Finder selection
- From: Steve Hayman <email@hidden>
- Date: Fri, 14 Oct 2005 10:13:15 -0400
Unfortunately this script doesn't work with more than one file
selected - how could I adapt the AppleScript to cope with a
selection of files?
What you can do is write a little shell loop to go through all of the
arguments. In the shell, the individual arguments are referred to as
$1, $2, $3 and so on, but the whole set of them is a special
variable, $@. So you can try doing something like this. (the
quotes are important to make this work with files with spaces in
their names!)
for f in "$@"
do
echo This is where I do something to each file in turn such as
cat "$f"
done
In fact, Automator will prepopulate the text of the Run Shell Script
action with a loop just like this, and it's even smart enough to know
what to do in different programming languages. Try adding a new Run
Shell Script action, and choose "Pass Input: as arguments" and then
try the different Shell settings on the popup. You'll notice that,
for instance, if you choose python, it fills in a starting loop like
this in the python language, which would be
import sys
for f in sys.argv[1:]:
print f
Nifty. Alternatively, depending on the command you have in mind you
may be able to cope with the entire list at once rather than doing a
loop. A simple example would be (using the regular bash shell)
# Copy the contents of all the files to one big honking file
cat "$@" >/tmp/oneBigHonkingFile
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Automator-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden