Hi All. I've been trying to learn something about Apple Events by working with Darryl Caldwell and Kevin Lindsey on a .pm for FileMaker Pro. Over the last couple days I've built a script that could prove to be pretty handy for other things. Here's the idea: I wrote an AppleScript to pull some data from a FMP database, and used Capture AE to see the equivalent Apple Event. I copied the Apple Event from Capture AE and pasted it into the __DATA__ part of this MacPerl script which converts the output from Capture AE into the equivalent MacPerl Apple Event and sends it. I've formatted my output in this version so I can cut and paste the results for use in building MacPerl modules. I've tried to generalize the script so it could be used for more than just my FMP hacking, and Darryl suggested I post it here. One other thing. I'm making a couple of assumptions about what MacPerl wants. I'm new to Apple Events and to MacPerl's corresponding modules. Would you folks who actually know this stuff double check my work here? I've only tested it with FileMaker Pro. Credit where it's due: this code is heavily borrowed from the examples in Chris Nandor's macperlcat.pod (thank's Chris!). Enjoy, and I welcome your feedback. -Eric Here's a test AppleScript: tell application "FileMaker Pro" every record of database "data.fp3" Â whose cell "field1" contains "ox" end tell which returns: {{"00005", "knox", "sox"}, {"00006", "fox", "box"}} Capture AE formats this as a single line even tho' my email will hard wrap it: Process("FileMaker Pro").SendAE "core,getd,'----':obj {form:test, want:type(crow), from:obj {form:name, want:type(cDB ), seld:"data.fp3", from:'null'()}, seld:cmpd{relo:cont, 'obj1':obj {form:name, want:type(ccel), seld:"field1", from:'exmn'()}, 'obj2':"ox"}}, &cons:[case]" My two assumptions (this is the stuff that really needs confirmation from someone with a better handle on MacPerl Apple Events): 1. Where Capture AE gives "form:xyz", MacPerl wants "form:enum(xyz)" 2. Capture AE's output includes ", &cons:[case]" on the end. MacPerl doesn't seem to like that, so my script strips it off. Here's the output from my script (hard wrapped again): $target = 'FMP3' $class = 'core' $id = 'getd' $params = "'----':obj {form:enum(test), want:type(crow), from:obj {form:enum(name), want:type(cDB ), seld:"data.fp3", from:'null'()}, seld:cmpd{relo:cont, 'obj1':obj {form:enum(name), want:type(ccel), seld:"field1", from:'exmn'()}, 'obj2':"ox"}}" core\getd{'----':obj {form:test, want:type(crow), from:obj {form:name, want:type(cDB ), seld:"data.fp3", from:'null'()}, seld:cmpd{relo:cont, 'obj1':obj {form:name, want:type(ccel), seld:"field1", from:'exmn'()}, 'obj2':"ox"}}, &inte:cans, &timo:3600} aevt\ansr{'----':[["00005", "knox", "sox"], ["00006", "fox", "box"]]} Last but not least, here's the script itself (with the above line from Capture AE included after __DATA__, hard wrapped by my emailer): #!perl -w use Mac::AppleEvents; use Mac::Processes; while(<DATA>) { if (m/^Process\("([^"]+)"\)\.SendAE /) { foreach $psi (values %Process) { next if ($1 ne $psi->processName()); $target = $psi->processSignature(); last; } die($^E) unless ($target); s/^Process\("[^"]+"\)\.SendAE //; m/^"([^,]+),([^,]+),(.*)"$/; $class = $1; $id = $2; $params = $3; $params =~ s/form:([A-Za-z0-9_]+),/form:enum(\1),/g; $params =~ s/},*[^,]*$/}/; } } printf "\$target = \'%s\'\n", $target; printf "\$class = \'%s\'\n", $class; printf "\$id = \'%s\'\n", $id; printf "\$params = \"%s\"\n\n", $params; $event = AEBuildAppleEvent( $class, $id, 'sign', $target,0, 0, $params ) || die($^E); $reply = AESend($event, kAEWaitReply) || die($^E); print AEPrint($event), "\n"; print AEPrint($reply), "\n"; AEDisposeDesc($event); AEDisposeDesc($reply); __DATA__ Process("FileMaker Pro").SendAE "core,getd,'----':obj {form:test, want:type(crow), from:obj {form:name, want:type(cDB ), seld:"data.fp3", from:'null'()}, seld:cmpd{relo:cont, 'obj1':obj {form:name, want:type(ccel), seld:"field1", from:'exmn'()}, 'obj2':"ox"}}, &cons:[case]" ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch