Hi

I've been trying off and on for a couple of days to run a script that requires parameters. The first problem I found was that NSAppleScript has a bug that wipes out QuarkXPress's event dictionary when loading scripts containing Quark commands. Someone pointed me to the OSAScript framework which doesn't have this bug, but I'm getting -1708 (errAEEventNotHandled) errors.

My code is running as a Quark XTension so I may be setting up the "targetAddress" incorrectly. Could someone take a look at the following snippet and point out where I'm messing up?

Thanks in advance

Here's what the NSLogs print to the console

> targetAddress: <NSAppleEventDescriptor: 'kpid'("QuarkXPress")>
> event: <NSAppleEventDescriptor: 'ascr'\'snam'{ '----': [ 'utxt'("Thursday, November 20, 2008") ] }> > subroutineDescriptor: <NSAppleEventDescriptor: 'utxt'("replacefoliodates")> > argsDescriptor: <NSAppleEventDescriptor: [ 'utxt'("Thursday, November 20, 2008") ]>
> result: (null)
> error: {
   OSAScriptErrorNumber = -1708;
} running script: AA_01-05


And here's the code:
Note: the "aeDescriptor" method in the line [inArguments aeDescriptor] is a category that coerces common types like NSArray, NSDictionaries, NSNumbers etc... into AEDescriptors.

// NOTE this method is a category on OSAScript
- (NSAppleEventDescriptor *) executeHandler: (NSString *) inHandler
                        withArguments: (id) inArguments
                        errorInfo: (NSDictionary **) inErrorInfo
{
        int                                                     pid             
                                = [[NSProcessInfo processInfo] 
processIdentifier];
        
NSAppleEventDescriptor *targetAddress = [[NSAppleEventDescriptor alloc] initWithDescriptorType: typeKernelProcessID
                                                                                    
                                            bytes: &pid
                                                                                
                                                length: sizeof(pid)];
                                                                                
                                                
NSAppleEventDescriptor *event = [[NSAppleEventDescriptor alloc] initWithEventClass: typeAppleScript
                                                                                
                                                eventID: keyASSubroutineName
                                                                                
                                                targetDescriptor: targetAddress
                                                                                
                                                returnID: kAutoGenerateReturnID
                                                                                
                                                transactionID: 
kAnyTransactionID],
*subroutineDescriptor = [NSAppleEventDescriptor descriptorWithString: [inHandler lowercaseString]],
                                                                *argsDescriptor 
                = [inArguments aeDescriptor];
                                                                
        NSAppleEventDescriptor          *result;
        
        NSLog(@"------------- targetAddress: %@", targetAddress);
        NSLog(@"------------- event: %@", event);
        NSLog(@"------------- subroutineDescriptor: %@", subroutineDescriptor);
        NSLog(@"------------- argsDescriptor: %@", argsDescriptor);

// Set up an AppleEvent descriptor containing the subroutine (handler) name
        [event setParamDescriptor: subroutineDescriptor forKeyword: 'snam'];

        // Add the provided arguments to the handler call
        [event setParamDescriptor: argsDescriptor forKeyword: keyDirectObject];

        // Execute the handler
        result = [self executeAppleEvent: event error: inErrorInfo];

        [targetAddress release];
        [event release];
        
        NSLog(@"------------- result: %@", result);
        

        return result;
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to