[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] calling Perl script from applescript



You wrote:
> Hi, I'm writing a program that combines an applecscript interacting
> with Quark with a PERL script that processes text files. How do I
> call the PERL perl script from within my applescript so that I can
> pass individual files via @ARGV. The applescript is a droplet that
> takes whatever folder it is fed and converts the Quark docs inside
> into TXT files. Ideally, I'd like for the PERL script to begin
> iterating through the directory once the Quark manipulations are
> done. I tried something (probably oversimplistic) that looks like
> this:
>
>
> tell application "Finder"
> tell folder sourcefiles
> set theTextDocs to (every file of entire contents of sourcefiles
> whose kind is not "alias" and the file type is "TXT")
> --in case there is only one item in the folder, coerce to list
> if the class of theTextDocs is not list then set theTextDocs to
> {theTextDocs}
> -- now iterate through the individual files
> repeat with theItem in theTextDocs
> set Tdoc to theItem as text
> tell application "MacPerl"
> @ARGV = (Tdoc)
> Do Script "&MacPerl'Converter(join(\",\",stat(\"MacPerl\")))"
> end tell
> end repeat
> end tell
> end tell
>
> It would probably be faster if the PERL script iterated through the
> folder on its own instead of relying on appleEvents to feed it new
> files every time, but I'm just beginning here so I don't know what
> the hell I'm doing. Anybody have any ideas? Any help would be
> really appreciated. Thanks,
>

I think taht this script sould be what you want.
I didn't tested it but this sould work :

--begin code--
#!perl

undef $/;

opendir(TEXTDOCS, $sourcefiles);
## we take only non-alias real files
@TextDocs = sort grep((-f)&& (!(-l)), readdir(TEXTDOCS));
closedir(TEXTDOCS);

foreach $item (@TextDocs) {
    next if !(-t $item); ## we work only with text files
    if(-e $item) {
        open(FILE, $item) or die "Error ",($!+0)," : $!\n";
        $Tdoc = <FILE>;  ## $Tdoc contains the whole file
        close(FILE);
        #
        # You can do your work now..
        # This place correspond where there is this line
        # in your AppleScript code :
        #   &MacPerl'Converter(join(\",\",stat(\"MacPerl\")));
        #
    }
}
--end code--

Just a question : what is this MacPerl'Converter() function ?
I can't find any reference of it at any place in the MacPerl FAQ
nor in macperl.pod

-------------------------
APERGHIS-TRAMONI Sebastien
Word Wide Web : http://www.resus.org/~madingue
E-Mail : madingue@cis.uni-muenchen.de
        (madingue@tango.resus.univ-mrs.fr)

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch