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

Re: [MacPerl] MacPerl->Applescript



At 11.13 1998.02.07, Shyam Hegde wrote:
>Thanks to Chris among others I have now got my MacPerl scripts correctly
>talking to Applescript... However I am stuck with one problem.
>
>Is there any way in MacPerl to pass more than just one string to
>AppleScript?? I would like to pass back about 4-5 strings to AppleScript
>and have them take seperate variables in AppleScript for passage back to
>Tango in the form of a list of lists
>{{"blah","subblah"},{"moreblah","somefoo","fooey"}}
>
>Has any of the MacPerl motley crew got any ideas - uptil now I have been
>using MacPerl::Reply but this will only ever pass 1 string back (and always
>the last one!)

Well, a few ideas:

1.)  Use multiple calls to MacPerl to get multiple pieces of data.

2.)  Use one call to MacPerl to return a single, delimited data structure
and split that up in AppleScript.

3.)  Use Apple Event handlers in MacPerl to return more than one piece of
data by, for example, returning an AE list.  Here is an example.  Run the
MacPerl script first, and then the AppleScript.  Of course, the problem
with this method is that one must have MacPerl sitting and waiting for the
event.

#========Perl Script==========
#!perl -w
use Mac::AppleEvents;
my($ok);

# set handler for app McPL and event id DATA
$AppleEvent{'McPL', 'DATA'} = \&RecData;
print "Starting ...\n";
while(!$ok){sleep(1)}
print "Done.\n";

sub RecData {
  my($event, $reply, $desc, $n, $list) = @_;
  $desc = AEGetParamDesc($event, keyDirectObject());
  $n = AEPrint($desc);
  $list = AECreateList('',0);
  AEPut($list, 1, typeChar(), $n);
  AEPut($list, 2, typeChar(),
    sprintf('%.f + %.f = %.f', $n, $n, $n+$n)
  );
  AEPutParamDesc($reply, keyDirectObject(), $list);
  print AEPrint($event), "\n";
  print AEPrint($reply), "\n";
  AEDisposeDesc($desc);
  AEDisposeDesc($list);
  $ok = 1;
  0;
}
__END__

#========AppleScript==========
tell application "MacPerl"
        Send Data 2.4
end tell

#========AppleScript==========
Reply: {"2.4000001", "2 + 2 = 5"}

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==               New Book:  MacPerl: Power and Ease               ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#



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