Mac::AppleEvents, Mostly Working

pudge on 2002-12-05T20:41:59

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)


linking with -lstdc++

rooneg on 2002-12-06T03:05:07

actually, you should probably be linking with g++, rather than gcc, if it's a program that has some c++ in it. that way g++ can take care of linking with whatever 'extra' libs c++ requires, and you won't have to worry about it.

Re:linking with -lstdc++

pudge on 2002-12-06T03:17:09

Why does it matter? I am ignorant in such matters. If there's nothing wrong with the approach I am using now, I am not too keen on trying something different. If it ain't broke, and all that.

Re:linking with -lstdc++

rooneg on 2002-12-06T03:24:35

it doesn't especially matter at the moment, but it insulates you from issues down the road if the gcc people decide to change the library you need for c++, or require an another lib or something. a lot of programs used to work fine under older versions of gcc even though they were linking with gcc instead of g++, but with more current versions of the compiler they refuse to link. if they had done the right thing (link a c++ program with the right tool for it, the c++ compiler/linker), then they wouldn't have had the problem.

Re:linking with -lstdc++

pudge on 2002-12-06T04:34:08

Hm. Well, then I would need to find out how to tell the Makefile to link using g++, in the Makefile.PL.