I have a Perl script that does some text transformation on a given file.
Now I would like to call this script from an AppleScript which in turn I could execute from the script menu in order to run the Perl script on a set of files with a choose folder prompt. My Perl script starts like this:
open my $in, '<', 'myfile.txt' or die "No input: $!";
open my $out, '>', 'myfile-modified.txt';
And then it does a bunch of search-and-replace and what not.
I would like to somehow call this script from an AppleScript and process multiple files. The AppleScript should look more or less like this:
set myFolder to choose folder with prompt "Choose a folder:"
tell application "Finder"
try
set myFiles to (every file in entire contents of myFolder whose name ends with ".txt") as alias list
on error
try
set myFiles to ((every file in entire contents of myFolder whose name ends with ".txt") as alias) as list
on error
set myFiles to {}
display dialog "No files in folder."
end try
end try
end tell
How can I run the Perl script from AppleScript while passing myFiles
as a variable to it (the perl script) and looping through them? I assume I have to do a do shell script
command but I don't know how to pass the variables on.
I also don't know whether it'd be better to pass the files as a file list to perl or to somehow put that into a repeat loop within AppleScript?