views:

34

answers:

1

I've seen plenty of examples on how to use NSAppleScript, e.g.:

NSAppleScript *script = = [[NSAppleScript alloc] initWithSource:source];
NSDictionary *errorDict;
if ( ![script compileAndReturnError:&errorDict] ) {
    // ...
}

But I've never seen any example code that does anything with errorDict. In my case, I'd like to extract the error message string. How does one do that?

+3  A: 

First, since the returned object is a dictionary, you can learn a lot about it by mere inspection. For instance, try adding the following to your if block;

NSLog(@"Got error dict %@", errorDict);

That will show you the named keys and values that are being returned to you.

Obviously it's better to use named constants for the keyed values, so consult the documentation here:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSAppleScript_Class/Reference/Reference.html#//apple_ref/c/data/NSAppleScriptErrorMessage

Search on "Error Dictionary Keys" for more information. To answer your specific question here, it sounds like you want either NSAppleScriptErrorBriefMessage or NSAppleScriptErrorMessage.

danielpunkass