From f52146424225e2d13a8fe7a29d703676c91d0d46 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Fri, 23 Jan 2004 01:48:56 +0000 Subject: [PATCH] ITOSAScript stuff. --- ITFoundation.h | 1 + ITFoundation.xcode/project.pbxproj | 45 ++++++++++++ ITOSAScript.h | 33 +++++++++ ITOSAScript.m | 108 +++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100755 ITOSAScript.h create mode 100755 ITOSAScript.m diff --git a/ITFoundation.h b/ITFoundation.h index 6a98fac..03a83a4 100755 --- a/ITFoundation.h +++ b/ITFoundation.h @@ -14,6 +14,7 @@ #import +#import #import #import diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index c3f2965..b8a2514 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -151,6 +151,8 @@ }; 08FB77AEFE84172EC02AAC07 = { children = ( + 370786C005C0B4D700E6D1BA, + 370786C105C0B4D700E6D1BA, 7CA50B2B054E77950074E1D9, 7CA50B2C054E77950074E1D9, 7CA50B2F054E77A00074E1D9, @@ -296,6 +298,47 @@ //322 //323 //324 +//370 +//371 +//372 +//373 +//374 + 370786C005C0B4D700E6D1BA = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = ITOSAScript.h; + refType = 4; + sourceTree = ""; + }; + 370786C105C0B4D700E6D1BA = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = ITOSAScript.m; + refType = 4; + sourceTree = ""; + }; + 370786C205C0B4D700E6D1BA = { + fileRef = 370786C005C0B4D700E6D1BA; + isa = PBXBuildFile; + settings = { + ATTRIBUTES = ( + Public, + ); + }; + }; + 370786C305C0B4D700E6D1BA = { + fileRef = 370786C105C0B4D700E6D1BA; + isa = PBXBuildFile; + settings = { + }; + }; +//370 +//371 +//372 +//373 +//374 //3D0 //3D1 //3D2 @@ -610,6 +653,7 @@ 8DC2EF510486A6940098B216, 7CA50D7E054E7C600074E1D9, 7CA50B2D054E77950074E1D9, + 370786C205C0B4D700E6D1BA, 7CA50B31054E77A00074E1D9, 3D2D8A13055E07D800F59C27, 2AB93A3205705A0C007E748F, @@ -650,6 +694,7 @@ 7CF6C931057D65B0007FEC13, 7CF6C939057D65BA007FEC13, 7C97DC2F05B614300013E85F, + 370786C305C0B4D700E6D1BA, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; diff --git a/ITOSAScript.h b/ITOSAScript.h new file mode 100755 index 0000000..8462951 --- /dev/null +++ b/ITOSAScript.h @@ -0,0 +1,33 @@ +/* + * ITFoundation + * ITOSAScript + * An extended NSAppleScript that allows any OSA language. + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * Responsibility : Joseph Spiros + * + * Copyright (c) 2002 - 2004 iThink Software. + * All Rights Reserved + * + */ + +#import +#import + +@interface ITOSAScript : NSObject { + NSString *_source; + unsigned long _scriptSubtype; +} + +- (id)initWithContentsOfFile:(NSString *)path; +- (id)initWithSource:(NSString *)source; + +- (NSString *)source; +- (void)setSource:(NSString *)newSource; +- (unsigned long)scriptSubtype; +- (void)setScriptSubtype:(unsigned long)newSubtype; + +- (NSString *)execute; + +@end diff --git a/ITOSAScript.m b/ITOSAScript.m new file mode 100755 index 0000000..6b079c8 --- /dev/null +++ b/ITOSAScript.m @@ -0,0 +1,108 @@ +/* + * ITFoundation + * ITOSAScript + * An extended NSAppleScript that allows any OSA language. + * + * Original Author : Kent Sutherland + * Responsibility : Kent Sutherland + * Responsibility : Joseph Spiros + * + * Copyright (c) 2002 - 2004 iThink Software. + * All Rights Reserved + * + */ + +/* +Script Subtypes: + kAppleScriptSubtype - AppleScript (Default) + 'Jscr' - JavaScript (if installed) +*/ + +#import "ITOSAScript.h" + +@implementation ITOSAScript + +- (id)init +{ + if ( (self = [super init]) ) { + _source = nil; + _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript + } + return self; +} + +- (id)initWithContentsOfFile:(NSString *)path +{ + if ( (self = [super init]) ) { + _source = [[NSString alloc] initWithContentsOfFile:path]; + _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript + } + return self; +} + +- (id)initWithSource:(NSString *)source +{ + if ( (self = [super init]) ) { + [self setSource:source]; + _scriptSubtype = kAppleScriptSubtype; //Default to AppleScript + } + return self; +} + +- (void)dealloc +{ + [_source release]; + [super dealloc]; +} + +- (NSString *)source +{ + return _source; +} + +- (void)setSource:(NSString *)newSource +{ + [_source release]; + _source = [newSource copy]; +} + +- (unsigned long)scriptSubtype +{ + return _scriptSubtype; +} + +- (void)setScriptSubtype:(unsigned long)newSubtype +{ + _scriptSubtype = newSubtype; +} + +- (NSString *)execute +{ + AEDesc scriptDesc, resultDesc; + Size length; + NSString *result; + Ptr buffer; + + AECreateDesc(typeChar, [_source cString], [_source cStringLength], &scriptDesc); + + OSADoScript(OpenDefaultComponent(kOSAComponentType, _scriptSubtype), &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc); + + length = AEGetDescDataSize(&resultDesc); + buffer = malloc(length); + + 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; + return result; +} + +@end -- 2.20.1