acidprime
acidprime

Reputation: 279

Parse a simple piece of text from a NSAppleEventDescriptor

So I have simple applescript that returns (return "test") the following:

NSAppleEventDescriptor: 'utxt'("test")

I found this question and tried to replicate what it was doing with the following code

NSAppleScript *scriptObject = [[NSAppleScript alloc]initWithContentsOfURL:[NSURL fileURLWithPath: scriptPath]
                                                                    error:&error];
returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
NSLog(@"Return Discriptor,%@",returnDescriptor);

NSAppleEventDescriptor *utxt = [returnDescriptor descriptorForKeyword:'utxt'];
NSLog(@"Found utxt Discriptor: %@",utxt);

NSString *scriptReturn = [utxt stringValue];
NSLog(@"Found utxt string: %@",scriptReturn);

but it is not returning anything:

Return Discriptor, Found utxt Discriptor: (null) Found utxt string: (null)

Upvotes: 0

Views: 2060

Answers (1)

regulus6633
regulus6633

Reputation: 19030

It seems to me that returnDescriptor is already the descriptor and you wouldn't need this: [returnDescriptor descriptorForKeyword:'utxt'];. I didn't test this code but give it a try...

NSDictionary *errorDict = nil;
NSAppleScript *scriptObject = [[NSAppleScript alloc]initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] error:&errorDict];
if (errorDict) {
   NSLog(@"Error: %@", errorDict);
   return;
}
NSAppleEventDescriptor *returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
if (errorDict) {
   NSLog(@"Error: %@", errorDict);
   [scriptObject release];
   return;
}

NSString *scriptReturn = [returnDescriptor stringValue];
NSLog(@"Found utxt string: %@",scriptReturn);
[scriptObject release];

Upvotes: 0

Related Questions