Mac::AppleEvents Working More

| | Comments (0)
Matthias tracked down a colleague who gave him a code snippet that worked for me. I don't know why the other didn't -- supposedly, it should have -- but this works, so I'm happy. Instead of AESend() it uses AESendMessage() (which doesn't use an idle proc), and it puts an attribute in the Apple event that says what port the process can receive messages on. So now I have perl on Mac OS X sending *and* receiving raw Apple events.

I don't have Apple events to remote machines working. I am not entirely sure why. I do know I have problems with it in Script Editor too, so it might not even be a problem with the Perl code at all. I think it might be, though: I can't find typeTargetID (which is the address type I use in Mac OS to send remote calls) anywhere in any of the headers. I think the method to do this has changed; maybe remote events use SOAP, maybe something else? I'll investigate later.

I also have a problem that is killing me with creating AEDescs. I have this code:

Ptr  theData;
Size theLength;
Handle data;  // contains "hi"
OSType type;  // contains "TEXT"
 
AEFail(AECreateDesc(type, *data, GetHandleSize(data), &RETVAL));
 
// test this, see what we have
theLength = AEGetDescDataSize(&RETVAL);
theData = malloc(theLength);
if (theData != NULL) {
    AEFail(AEGetDescData(&RETVAL, theData, theLength));
    printf("%d:%s:%d\n", theLength, theData, strlen(theData));
}

Now, *data contains "hi" and GetHandleSize(data) is 2. theLength is 2. But after AEGetDescData(), theData contains "hi5{" and strlen(theData) is 4. No matter what I do, if the string is 2 bytes, "5{" is tacked onto the end. If it is 3, "{" is tacked on. If the data is 1 or more than 3 bytes, it comes out fine. It's freaking me out.

So, I have bunches of little bugs like this. The GUSI* routines are working pretty well, but totally bail if the target file does not exist, which is a very wrong thing to do. It might take total reengineering. Yuck.

The AEBuild error code for $@ is acting up a little; for some reason it is displaying an error when there should be none. But I am resisting the temptation to look into it now, and instead am just noting it, as I am taking the weekend off.

I also need to work on Mac::AppleEvents::Simple some, though it seems to be fine except for the remote calls. So far. I'm sure I'll find more. Mac::Apps::Launch and Mac::Processes need an overhaul for launching processes on Mac OS X. The old calls I use sorta work, but not really, and they are slow.

I hope to release Mac::Carbon 0.02 next week, and then continue to iron out these other bugs and things for a Mac::Carbon 0.03 next year, along with updates to Mac::Apps::Launch and Mac::AppleEvents::Simple (sold separately). Then, when I am satisfied it is working reasonably well, I'll do Mac::Glue. 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 6, 2002 6:05 PM.

Mac::AppleEvents, Now With Special Sauce was the previous entry in this site.

Name That Superhero is the next entry in this site.

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