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

Re: [MacPerl] Droplets that handle arbitrary events?



At 18.38 1998.02.27, Stephan Somogyi wrote:
>Since I imagine it will be straightforward to send AppleEvents to
>LetterRip and receive replies thanks to AppleEvents.pm, I'm mainly
>concerned about receiving the right events from the outset.

Not sure what you want.  Would the script run and wait for an AppleEvent to
talk to it?

You can set up an event handler for MacPerl's Send Data ('DATA') event and
handle it however you want.  You get passed $event and $reply to your
handler, and you pull out and stick in data as you like; $reply is returned
to the caller app when the handler is done, returning 0.  Setting up an
event handler in MacPerl:

  #!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, $c) = @_;
    $desc = AEGetParamDesc($event, keyDirectObject());
    $c = AECountItems($desc);
    foreach (1..$c) {
      $n = AEGetNthDesc($desc, $_);
      print AEPrint($n), "\n";
      AEDisposeDesc($n);
    }
    foreach ('q'..'z') {
      AEPut($desc, ++$c, 'TEXT', $_)
    }
    AEPutParamDesc($reply, keyDirectObject(), $desc);
    print AEPrint($event), "\n";
    print AEPrint($reply), "\n";
    $ok = 1;
    0;
  }


The calling it via this AppleScript:

  tell application "MacPerl"
    set myList to {"a", "b", "c", "d", "e", "f", "g"}
    return Send Data myList
  end tell

Hope this helps,

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