i want to use a MacPerl script which is called from another application, i.e. CMacTeX's pdftex. I thought i could save the script as droplet and access parameters given to the script during the call with @ARGV. But the array is empty.
The script below demonstrates how to pass arguments to a script. Although the dictionary does not mention arguments in the Do Script entry, these are passed as items of a list, the first item of which is the script text.
In this case I create test.pl with AS for the purposes of the demonstration but it would normally be a pre-existing file.
-- Preparation of test script set |test.pl| to " for (@ARGV) { ++$i ; print qq~$i\\.\\t$_\\n~ }" set f to (path to desktop as string) & ¬ "test.pl" as file specification open for access f with write permission write |test.pl| to f close access f -- end preparation
tell application "MacPerl" set _script to read f Do Script {_script, "a", "b", "c"} mode Batch end tell
If you want to pass arguments to an AppleScript applet, then create a doPerlScript handler like this in the applet. You can then send events to tell the applet to doPerlScript with a list as parameter the first item of which is the pathname of the perl script and the rest the argument list @ARGV.
I use mode batch here just to check the results in Script Editor. You would not need it otherwise.
set _perlscript to (path to desktop as string) & ¬ "test.pl" as file specification
doPerlScript( {_perlscript, "a", "b", "c"} )
on doPerlScript(_list) set _scriptPath to "" & first item in _list set _script to read file _scriptPath set the first item in the _list to the _script tell application "MacPerl" to Do Script _list mode Batch end doPerlScript
JD