I didn't find this anywhere, so I cooked it up myself. The gist is that you can pre-compile your AppleScripts and pass arguments to them via Terminal -- no need to dynamically generate and compile the scripts via the osascript command.
Read the rest of the hint for the how-to...Here is how it is done:
cpan command or how ever you prefer. osarun) with the following contents:
#!/usr/bin/perl
use strict;
use Mac::AppleScript qw/ RunAppleScript /;
if( $#ARGV = 0) ? '"'.join('","',@ARGV).'"' : "";
my $rtn = RunAppleScript( "return run script alias ((POSIX file ""
.$script.'") as text) with parameters {'.$args.'}' ),"n"
or die "AppleScript Error: $!";
$rtn =~ s/(^"|"$)//g;
print $rtn,"n";
Feel free to make this more user friendly.... Save this file on your PATH and make it executable.
on run argv
set rtn to ((count of argv) as text) & " parameters passed.
The parameters were:
"
repeat with arg in argv
set rtn to rtn & " " & (arg as text) & "
"
end repeat
return rtn
end run
The variable argv will be a list of the command line arguments; do anything you want with them. Be sure to save your script as a script or application (just not as text). You can also use osacompile to compile scripts.
osarun Callee.scpt test "second test"
This should give you the output:
2 parameters passed. The parameters were: test second test
That's it. Now go crazy. Write AppleScripts.
Mac OS X Hints
http://hints.macworld.com/article.php?story=2004012913110734