I have validated my app as scriptable and constructed the suite within a.sdef file, and when I send a command through appleScript editor, I reach the right class (for me SolarMaxAppleEvent class) and process performDefaultImplementation method, which returns a NSString.
This class has been intanciated by my app which fills in an array (NSMutableArray * AppleEventUpsArray) of Dictionaries (NSMutableDictionary * appleEventUpsDict) which I want to use in AppleScript Answer.
In order to fill in this string, I need to acces to this AppleEventUpsArray property in performDefaultImplementation method.
But running inside this method (with debug) it seems, that I cannot access to the same instance than in the one filled by the app.
How can I access within performDefaultImplementation method to the properties of this class?
Sample code follows:
file: SolarMaxAppleEvent.h
@interface SolarMaxAppleEvent : NSScriptCommand {
@public NSMutableArray *AppleEventUpsArray;
@public NSMutableDictionary *appleEventUpsDict;
}
- (id)performDefaultImplementation;
@property (nonatomic, retain) NSMutableArray *AppleEventUpsArray;
@property (nonatomic, retain) NSMutableDictionary *appleEventUpsDict;
@end
file: SolarMaxAppleEvent.m
@implementation SolarMaxAppleEvent
@synthesize AppleEventUpsArray;
@synthesize appleEventUpsDict;
-
(id)init {
int i;
if (self = [super init]) {
// NSLog(@"SolarMaxAppleEvent init ");
self.AppleEventUpsArray = [[NSMutableArray alloc] init]; for (i=0 ; i< 3 ; i++) { appleEventDict = [[NSMutableDictionary alloc] init]; appleEventDict = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSDate date], @"Date", [NSNumber numberWithInteger: 0 ], @"numPort", [NSNumber numberWithInteger: 0 ],@"UAC" , [NSNumber numberWithInteger: 0 ],@"PAC" , [NSNumber numberWithInteger: 0 ],@"Temp", [NSNumber numberWithInteger: 0 ],@"UDC" ,nil ]; [self.AppleEventUpsArray addObject: appleEventDict]; [appleEventDict release]; } NSLog(@"SolarMaxAppleEvent init AppleEventUpsArray : %@ ",AppleEventUpsArray);
// at this point This AppleEventUpsArray is correctly filled with 3 objects (when seen in apple Debugger)
}
return self;
}
// Following request from apple script, program enters this following method.
-
(id) performDefaultImplementation {
id currentEventArray;
NSDictionary * theArguments = [self evaluatedArguments];
NSString *theResult;
SLOG(@“CommandWithArgs performDefaultImplementation”);
/* report the parameters */
SLOG(@“The direct parameter is: ‘%@’”, [self directParameter]);
SLOG(@“The other parameters are: ‘%@’”, theArguments); // I clearly see this Log within console with the rignt arguments
currentEventArray = self.AppleEventUpsArray; theResult = [NSString stringWithFormat:@"'%@'", [self.currentEventArray count]];
// which returns 0 to apple script command instead of 3 and debugger indicates that self.AppleEventUpsArray pointer is 0
SLOG (@"Result Sent %@" ,theResult);
return theResult;
}
// Question: How can I access to AppleEventUpsArray within performDefaultImplementation?
// Which bind operation, or class declaration (in sdef file) must I declare to share the same values between apple script command and X code application ?
Thanks for your answer.