4 * An extended NSAppleScript that allows any OSA language.
6 * Original Author : Kent Sutherland <ksutherland@ithinksw.com>
7 * Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
8 * Responsibility : Joseph Spiros <joseph.spiros@ithinksw.com>
10 * Copyright (c) 2002 - 2004 iThink Software.
17 kAppleScriptSubtype - AppleScript (Default)
18 'Jscr' - JavaScript (if installed)
21 #import "ITOSAScript.h"
22 #import "ITOSAComponent.h"
24 #warning To do - Error Dictionaries
26 @implementation ITOSAScript
30 return nil; // initWithSource: is the designated initializer for this class
33 - (id)initWithContentsOfFile:(NSString *)path
35 return [self initWithSource:[[[NSString alloc] initWithContentsOfFile:path] autorelease]];
38 - (id)initWithSource:(NSString *)source
40 if ( (self = [super init]) ) {
41 _source = [source copy];
42 _scriptID = kOSANullScript;
49 if (_scriptID != kOSANullScript) {
50 OSADispose([_component componentInstance], _scriptID);
62 - (ITOSAComponent *)component
67 - (void)setComponent:(ITOSAComponent *)newComponent
69 _component = newComponent;
72 - (BOOL)compileAndReturnError:(NSDictionary **)errorInfo
74 if ([_component componentInstance] == nil) {
75 //Set the error dictionary
80 AECreateDesc(typeChar, [_source cString], [_source cStringLength], &moof);
81 if (OSACompile([_component componentInstance], &moof, kOSAModeNull, &_scriptID) != 0) {
82 NSLog(@"Compile error!");
90 return (_scriptID != kOSANullScript);
93 - (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo
95 if ([_component componentInstance] == nil) {
96 //Set the error dictionary
100 NSAppleEventDescriptor *cocoaDesc;
102 AEDesc scriptDesc, resultDesc;
103 OSAID resultID = kOSANullScript;
105 //If not compiled, compile it
106 if (![self isCompiled]) {
107 if (![self compileAndReturnError:nil]) {
108 //Set the error info dictionary
113 OSAExecute([_component componentInstance], _scriptID, kOSANullScript, kOSANullMode, &resultID);
115 OSACoerceToDesc([_component componentInstance], resultID, typeWildCard, kOSAModeNull, &resultDesc); // Using this instead of OSADisplay, as we don't care about human readability, but rather, the integrity of the data.
117 cocoaDesc = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc];
119 AEDisposeDesc(&scriptDesc);
121 OSADispose([_component componentInstance], resultID);