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

Re: [MacPerl] MacPerl->Applescript



I just wrote:
# At 11.13 1998.02.07, Shyam Hegde wrote:
# >{{"blah","subblah"},{"moreblah","somefoo","fooey"}}
# 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.

I should have noted how you might want to have a list of lists.  Here you
are.  Using the same AppleScript as before, you get the result:

    {{"2.4000001", "2.4000001", "4.8000002"}, {"2 + 2 = 5"}}

#!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, $list1, $list2, $list3) = @_;
  $desc = AEGetParamDesc($event, keyDirectObject());
  $n = AEPrint($desc);
  $list1 = AECreateList('',0);
  $list2 = AECreateList('',0);
  $list3 = AECreateList('',0);
  AEPut($list1, 1, typeChar(), $n);
  AEPut($list1, 2, typeChar(), $n);
  AEPut($list1, 3, typeChar(), $n+$n);
  AEPut($list2, 1, typeChar(),
    sprintf('%.f + %.f = %.f', $n, $n, $n+$n)
  );
  AEPutDesc($list3, 1, $list1);
  AEPutDesc($list3, 2, $list2);
  AEPutParamDesc($reply, keyDirectObject(), $list3);
  print AEPrint($event), "\n";
  print AEPrint($reply), "\n";
  AEDisposeDesc($desc);
  AEDisposeDesc($list1);
  AEDisposeDesc($list2);
  AEDisposeDesc($list3);
  $ok = 1;
  0;
}

--
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