Mac::AppleEvents, Mostly Working

| | Comments (0)
Last night's problem was solved by adding "-lstdc++" to the linker flags. Thanks, Matthias!

So today, I get it working, and I try a simple script:

use Mac::AppleEvents;
$evt = AEBuildAppleEvent(qw(misc actv sign MACS), -1, 0, "");
AESend($evt, kAENoReply);

And sure enough, it activates the Finder. This is the equivalent of the AppleScript:

tell app "Finder" to activate

Sweet. I've even tried some more complex things, opening a directory in the Finder, using the Mac::AppleEvents::Simple frontend:

use Mac::AppleEvents::Simple ':all';
 
$evt = build_event(qw(aevt odoc MACS),
    q{'----':obj { want:type(cobj), from:null(), form:enum(name), seld:TEXT(@)}}
    "Orr:Users:pudge:"  # yes, AEGizmos requires HFS paths
);
$evt->send_event(kAENoReply);

Or, using aliases:

use Mac::AppleEvents::Simple ':all';
use Mac::Files;
 
$evt = build_event(qw(aevt odoc MACS), q{'----':alis(@@)}, NewAlias("/Users/pudge/")); $evt->send_event(kAENoReply)'

All looks good so far. But, you may ask, why kAENoReply? Sure, I don't need the reply, but why bother not waiting, as per the default? There's the big remaining problem: I can't receive a reply. I have an idle proc that appears to be working -- as is needed to receive a reply -- but it's not getting the event back. I was afraid of this. In Mac OS, you need to set a flag that says your application can receive high-level events (such as Apple events). But how to do this for perl? No idea. Working on a solution, but in the meantime, polishing and playing.

I also still need to port the AESubDescs (for subdescriptors) and AEStreams (an OO interface to handling Apple event data) stuff, but they are rarely used, and are a lower priority than just getting this to work. I'll be more than happy to add them back in later, if I can.

Now Playing: Found a Home - Jon Gibson (Forever Friends)

use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on December 5, 2002 12:41 PM.

MacPerl 5.6.1r2 Released was the previous entry in this site.

Mac::AppleEvents, Now With Special Sauce is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.