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

[MacPerl] AppleEvent help?



Has anybody used AppleEvents in MacPerl to drive MacPerl? The only help I
can find is the little AESend/Receive thingy and Matthias's Anarchist's
Cookbook stuff, none of which really seem to help me. (Well, the AE Receive
thing did help me figure out what objects the ScriptEditor was sending to
MacPerl, but when I try to use those objects from within the MacPerl
AEBuildAppleEvent call, they don't work.)

What I'd like to do is to be able to close windows, count the number of
open windows, move windows, resize windows, count the number of lines, etc.
I know next to nothing about AppleEvents, which may be the real cause of my
frustration. In the example below, the first two things work (closing
windows.) I'm stuck, though, on getting the third (count the number of
lines) to work.

Although I don't think I'm ever going to really appreciate the whole AE
model of objects, etc, I would really love to get away from using
AppleScript (which, as was recently pointed out, is the really slow way of
communication with MacPerl.)

Anybody have any code similar to this? (Or should I give up and start using
the new toolbox routines, and hope my users can install the new version?...)

#!perl
use Mac::AppleEvents;

# to close a window by index (this works)
$wind = "obj{want:type(cwin), from:null(), form:indx, seld:0}";
$evt = AEBuildAppleEvent("core", "clos", typeApplSignature, "McPL", 0,0,

        "'----': $wind", ) or die $^E;

# to close a window by name (this works) (curly quotes around "Untitled")
$wind = "obj{want:type(cwin), from:null(), form:name, seld:"Untitled"}";
$evt = AEBuildAppleEvent("core", "clos", typeApplSignature, "McPL", 0,0,

        "'----': $wind", ) or die $^E;

# to (try to) count the lines in window 1 (this fails)
$windCnt = "obj {want:type(clin), form:indx, seld:abso(all), from:obj ".
        "{want:type(cwin), form:indx, seld:1, from:null()}}";
$evt = AEBuildAppleEvent("core", "cnte", typeApplSignature, "McPL", 0,0,

        "'----': $windCnt, obj:type(clin) ", ) or die $^E;

$rep = AESend($evt, kAEWaitReply) or die $^E;

print "Reply was: ", AEPrint($rep), "\n";

AEDisposeDesc $evt;
AEDisposeDesc $rep;


-dan



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