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 @implementation ITOSAScript
28 if ( (self = [super init]) ) {
34 - (id)initWithContentsOfFile:(NSString *)path
36 if ( (self = [super init]) ) {
37 _source = [[NSString alloc] initWithContentsOfFile:path];
42 - (id)initWithSource:(NSString *)source
44 if ( (self = [super init]) ) {
45 [self setSource:source];
61 - (void)setSource:(NSString *)newSource
64 _source = [newSource copy];
67 - (ITOSAComponent *)component
72 - (void)setComponent:(ITOSAComponent *)newComponent
74 _component = newComponent;
89 AEDesc scriptDesc, resultDesc;
94 AECreateDesc(typeChar, [_source cString], [_source cStringLength], &scriptDesc);
96 OSADoScript([_component componentInstance], &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
98 length = AEGetDescDataSize(&resultDesc);
99 buffer = malloc(length);
101 AEGetDescData(&resultDesc, buffer, length);
102 AEDisposeDesc(&scriptDesc);
103 AEDisposeDesc(&resultDesc);
104 result = [NSString stringWithCString:buffer length:length];
105 if (![result isEqualToString:@""] &&
106 ([result characterAtIndex:0] == '\"') &&
107 ([result characterAtIndex:[result length] - 1] == '\"'))
109 result = [result substringWithRange:NSMakeRange(1, [result length] - 2)];