Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Thursday December 05, 2002
03:41 PM

Mac::AppleEvents, Mostly Working

[ #9296 ]

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)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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.
    • 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.
      • 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 h