How to resolve an unknown AppleEvent address type?

Our app uses a NSUserAppleScriptTask to capture the users context and provide contextual content. While our approach works fine for macOS High Sierra, the app thriws an error with macOS Catalina:


Script execution failed: The operation couldn’t be completed. /Users/.../Default.scpt: script error: Unknown AppleEvent address type. (-1716)

If we call the script with the Script Editor everything is fine. I assume we have to use different parameters for the NSAppleEventDescriptor for macOS Cataline. Here is the relevant code snipped:


NSAppleEventDescriptor *paramter = [NSAppleEventDescriptor listDescriptor];
[paramter insertDescriptor:[NSAppleEventDescriptor descriptorWithString:bundleId] atIndex:0];
   
NSAppleEventDescriptor *event = [NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite
                                                                         eventID:kASSubroutineEvent
                                                                targetDescriptor:nil
                                                                        returnID:kAutoGenerateReturnID
                                                                   transactionID:kAnyTransactionID];
[event setDescriptor:[NSAppleEventDescriptor descriptorWithString:@"getContext"] forKeyword:keyASSubroutineName];
[event setDescriptor:paramter forKeyword:keyDirectObject];
   
NSUserAppleScriptTask *script = [[NSUserAppleScriptTask alloc] initWithURL:scriptURL error:&fileError];
   
...
   
[script executeWithAppleEvent:event completionHandler:^(NSAppleEventDescriptor * _Nullable result, NSError * _Nullable error) {
   ...
}

Apples error documentation says:


-1716

The target address type of an Apple event is unknown


I think, Cataline doesn't accept, that the targetDescriptor parameter is nil. However the developer documentation says:

A pointer to a descriptor that identifies the target application for the Apple event. Passing

nil
results in an Apple event descriptor that has no
keyAddressAttr
attribute (it is valid for an Apple event to have no target address attribute).

Has someone any idea for a solution?

Replies

I don’t see anything fundamentally wrong with your approach, so if it’s existing code that’s failing on 10.15 beta then I recommend that you file a compatibility bug about it. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for your answer. The solution was quite simple. I had to remove the script folder of the app, so that the directory was re-created. I think it was a security issue, because the directory was created by the app from the store and I tested this feature with a build from Xcode.