Replying to an Apple Event in Cocoa

908 views Asked by At

I'm registering an Apple Event handler using NSAppleEventManager:

[[NSAppleEventManager sharedAppleEventManager]
    setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:)
      forEventClass:kInternetEventClass andEventID:kAEGetURL];

My handler method will, of course, receive the event and a reply event:

- (void) handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
    //Open this URL; reply if we can't
}

So, if I need to reply with an error, indicating that I failed in some way to open this URL, how should I use the replyEvent to do that?

1

There are 1 answers

2
Ken Thomases On

I have translated the following from the old-style C procedural API described in Apple's legacy document "Apple Events Programming Guide" to Cocoa:

if ([replyEvent descriptorType] != typeNull)
{
    [replyEvent setParamDescriptor:[NSAppleEventDescriptor descriptorWithInt32:someStatusCode] forKeyword:keyErrorNumber];
    [replyEvent setParamDescriptor:[NSAppleEventDescriptor descriptorWithString:someErrorString] forKeyword:keyErrorString];
}

See "Returning Error Information" in the "Apple Events Programming Guide" (in the Legacy library).