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"
23 @implementation ITOSAScript
27 if ( (self = [super init]) ) {
29 _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript
34 - (id)initWithContentsOfFile:(NSString *)path
36 if ( (self = [super init]) ) {
37 _source = [[NSString alloc] initWithContentsOfFile:path];
38 _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript
43 - (id)initWithSource:(NSString *)source
45 if ( (self = [super init]) ) {
46 [self setSource:source];
47 _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript
63 - (void)setSource:(NSString *)newSource
66 _source = [newSource copy];
69 - (unsigned long)scriptSubtype
71 return _scriptSubtype;
74 - (void)setScriptSubtype:(unsigned long)newSubtype
76 _scriptSubtype = newSubtype;
81 AEDesc scriptDesc, resultDesc;
86 AECreateDesc(typeChar, [_source cString], [_source cStringLength], &scriptDesc);
88 OSADoScript(OpenDefaultComponent(kOSAComponentType, _scriptSubtype), &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
90 length = AEGetDescDataSize(&resultDesc);
91 buffer = malloc(length);
93 AEGetDescData(&resultDesc, buffer, length);
94 AEDisposeDesc(&scriptDesc);
95 AEDisposeDesc(&resultDesc);
96 result = [NSString stringWithCString:buffer length:length];
97 if (![result isEqualToString:@""] &&
98 ([result characterAtIndex:0] == '\"') &&
99 ([result characterAtIndex:[result length] - 1] == '\"'))
101 result = [result substringWithRange:NSMakeRange(1, [result length] - 2)];