From f8ec7fef60702faee580b27778bb677036bb30e5 Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Thu, 29 Jan 2004 03:08:23 +0000 Subject: [PATCH] Some API changes... of note, ITOSAScript's execution API returns an NSAppleEventDescriptor. --- ITOSAComponent.h | 2 +- ITOSAComponent.m | 4 +++- ITOSAScript.h | 4 +++- ITOSAScript.m | 38 ++++++++++---------------------------- 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/ITOSAComponent.h b/ITOSAComponent.h index a36fab6..a552aad 100755 --- a/ITOSAComponent.h +++ b/ITOSAComponent.h @@ -20,7 +20,7 @@ ComponentInstance _componentInstance; NSDictionary *_information; } -+ (ITOSAComponent *)AppleScriptComponent; ++ (ITOSAComponent *)appleScriptComponent; + (ITOSAComponent *)componentWithCarbonComponent:(Component)component; + (NSArray *)availableComponents; diff --git a/ITOSAComponent.m b/ITOSAComponent.m index 0205e7e..0b28ad9 100755 --- a/ITOSAComponent.m +++ b/ITOSAComponent.m @@ -14,9 +14,11 @@ #import "ITOSAComponent.h" +#warning Need to add a constant data store containing all available component instances... could be lazy and build it on class +load. + @implementation ITOSAComponent -+ (ITOSAComponent *)AppleScriptComponent ++ (ITOSAComponent *)appleScriptComponent { return [[[ITOSAComponent alloc] initWithSubtype:kAppleScriptSubtype] autorelease]; } diff --git a/ITOSAScript.h b/ITOSAScript.h index 7c8d337..547acc6 100755 --- a/ITOSAScript.h +++ b/ITOSAScript.h @@ -27,11 +27,13 @@ - (id)initWithSource:(NSString *)source; - (NSString *)source; + - (ITOSAComponent *)component; - (void)setComponent:(ITOSAComponent *)newComponent; - (BOOL)compileAndReturnError:(NSDictionary **)errorInfo; - (BOOL)isCompiled; -- (NSString *)executeAndReturnError:(NSDictionary **)errorInfo; + +- (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo; @end diff --git a/ITOSAScript.m b/ITOSAScript.m index 5a20ef3..675b3ac 100755 --- a/ITOSAScript.m +++ b/ITOSAScript.m @@ -21,23 +21,18 @@ Script Subtypes: #import "ITOSAScript.h" #import "ITOSAComponent.h" +#warning To do - Error Dictionaries + @implementation ITOSAScript - (id)init { - if ( (self = [super init]) ) { - _source = nil; - } - return self; + return nil; // initWithSource: is the designated initializer for this class } - (id)initWithContentsOfFile:(NSString *)path { - if ( (self = [super init]) ) { - _source = [[NSString alloc] initWithContentsOfFile:path]; - _scriptID = kOSANullScript; - } - return self; + return [self initWithSource:[[[NSString alloc] initWithContentsOfFile:path] autorelease]]; } - (id)initWithSource:(NSString *)source @@ -95,17 +90,16 @@ Script Subtypes: return (_scriptID != kOSANullScript); } -- (NSString *)executeAndReturnError:(NSDictionary **)errorInfo +- (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo { if ([_component componentInstance] == nil) { //Set the error dictionary return nil; } + NSAppleEventDescriptor *cocoaDesc; + AEDesc scriptDesc, resultDesc; - Size length; - NSString *result; - Ptr buffer; OSAID resultID = kOSANullScript; //If not compiled, compile it @@ -118,27 +112,15 @@ Script Subtypes: OSAExecute([_component componentInstance], _scriptID, kOSANullScript, kOSANullMode, &resultID); - OSADisplay([_component componentInstance], resultID, typeChar, kOSAModeDisplayForHumans, &resultDesc); + 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. - length = AEGetDescDataSize(&resultDesc); - buffer = malloc(length); + cocoaDesc = [[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc]; - AEGetDescData(&resultDesc, buffer, length); AEDisposeDesc(&scriptDesc); - AEDisposeDesc(&resultDesc); - result = [NSString stringWithCString:buffer length:length]; - if (![result isEqualToString:@""] && - ([result characterAtIndex:0] == '\"') && - ([result characterAtIndex:[result length] - 1] == '\"')) - { - result = [result substringWithRange:NSMakeRange(1, [result length] - 2)]; - } - free(buffer); - buffer = NULL; OSADispose([_component componentInstance], resultID); - return result; + return cocoaDesc; } @end -- 2.20.1