I want to know if it's possible, in case of execution error, to retrive also the Applescript error number / message / ... and not only the normal return value.
In the Apple Class Reference site I have found this information, I have tried to modify the originale code, but after many hours I don't have found the right way to do this thing.
https://developer.apple.com/library/mac ... rence.html
"Error Dictionary Keys
If the result of initWithContentsOfURL:error:, compileAndReturnError:, executeAndReturnError:, or executeAppleEvent:error:, signals failure (nil, NO, nil, or nil, respectively), a pointer to an autoreleased dictionary is put at the location pointed to by the error parameter. The error info dictionary may contain entries that use any combination of the following keys, including no entries at all.
extern NSString *NSAppleScriptErrorMessage;
extern NSString *NSAppleScriptErrorNumber;
extern NSString *NSAppleScriptErrorAppName;
extern NSString *NSAppleScriptErrorBriefMessage;
extern NSString *NSAppleScriptErrorRange;"
Thank you for any suggestion
Calling AppleScript
Code:
Code: Select all
Procedure.s AppleScript(Script.s)
Protected retVal.s, strVal, numItems, i
Protected aScript = CocoaMessage(0, CocoaMessage(0, CocoaMessage(0, 0, "NSAppleScript alloc"), "initWithSource:$", @Script), "autorelease")
Protected eventDesc = CocoaMessage(0, aScript, "executeAndReturnError:", #nil)
If eventDesc
numItems = CocoaMessage(0, eventDesc, "numberOfItems")
If numItems
For i = 1 To numItems
strVal = CocoaMessage(0, CocoaMessage(0, eventDesc, "descriptorAtIndex:", i), "stringValue")
If strVal
retVal + PeekS(CocoaMessage(0, strVal, "UTF8String"), -1, #PB_UTF8)
If i <> numItems : retVal + #LF$ : EndIf
EndIf
Next
Else
strVal = CocoaMessage(0, eventDesc, "stringValue")
If strVal : retVal = PeekS(CocoaMessage(0, strVal, "UTF8String"), -1, #PB_UTF8) : EndIf
EndIf
EndIf
ProcedureReturn retVal
EndProcedure
