Permalink
Browse files

Applescript support now correctly encodes dictionaries and arrays whe…

…n passing them to the script.
  • Loading branch information...
Grayson committed Feb 7, 2009
1 parent 861fe77 commit 1843c86afa70e93092ccd93743e8eea8f5392f32
Showing with 19 additions and 3 deletions.
  1. +3 −2 src/ApplescriptPluginManager.m
  2. +16 −1 src/NSApplescript+FCSAdditions.m
@@ -52,11 +52,10 @@ -(void)build
{
NSAppleScript *as = [NSAppleScript appleScriptWithContentsOfFile:path];
if (!as) continue;
+
NSAppleEventDescriptor *desc = [NSAppleEventDescriptor appleEventWithEventClass:ASPluginAppClassCode() eventID:ASPluginPropertyEventCode targetDescriptor:procDesc returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
id err = nil;
NSAppleEventDescriptor *ret = [as executeAppleEvent:desc error:&err];
- NSLog(@"%s %@", _cmd, err);
- NSLog(@"%s %@", _cmd, ret);
if (ret)
{
NSString *property = [ret stringValue];
@@ -77,6 +76,7 @@ -(NSArray *)pluginsForProperty:(NSString *)property forValue:(id)forValue withVa
if (!arr || ![arr count]) return nil;
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
+ NSLog(@"%s %@ %@", _cmd, NSStringFromClass([forValue class]), NSStringFromClass([withValue class]));
if (forValue) [parameters setObject:forValue forKey:[NSNumber numberWithUnsignedLong:ASPluginForCode]];
if (withValue) [parameters setObject:withValue forKey:[NSNumber numberWithUnsignedLong:ASPluginWithCode]];
@@ -87,6 +87,7 @@ -(NSArray *)pluginsForProperty:(NSString *)property forValue:(id)forValue withVa
while (as = [e nextObject])
{
NSAppleEventDescriptor *enabledDesc = [as executeEvent:ASPluginEnableEventCode eventClass:ASPluginAppClassCode() parameters:parameters];
+ NSLog(@"%s THERE", _cmd);
if (enabledDesc && [enabledDesc booleanValue])
{
NSAppleEventDescriptor *desc = [as executeEvent:ASPluginTitleEventCode eventClass:ASPluginAppClassCode() parameters:parameters];
@@ -61,8 +61,9 @@ -(NSAppleEventDescriptor *)executeEvent:(AEEventID)eventCode eventClass:(AEEvent
NSEnumerator *e = [parameters keyEnumerator];
NSNumber *key = nil;
- while (key = [e nextObject])
+ while (key = [e nextObject]) {
[desc setParamDescriptor:[[parameters objectForKey:key] ASDescriptor] forKeyword:[key unsignedLongValue]];
+ }
NSDictionary *errorDict = nil;
NSAppleEventDescriptor *returnDesc = [self executeAppleEvent:desc error:&errorDict];
@@ -128,6 +129,20 @@ -(NSAppleEventDescriptor *)ASDescriptor
desc = [NSAppleEventDescriptor descriptorWithString:(NSString *)self];
else if ([self isKindOfClass:[NSNumber class]])
desc = [NSAppleEventDescriptor descriptorWithInt32:[(NSNumber *)self intValue]];
+ else if ([self isKindOfClass:[NSDictionary class]]) {
+ desc = [NSAppleEventDescriptor recordDescriptor];
+ NSMutableArray *items = [NSMutableArray array];
+ for (NSString *key in [(NSDictionary *)self allKeys]) {
+ [items addObject:key];
+ [items addObject:[(NSDictionary *)self objectForKey:key]];
+ }
+ [desc setParamDescriptor:[items ASDescriptor] forKeyword:'usrf'];
+ }
+ else if ([self isKindOfClass:[NSArray class]]) {
+ desc = [NSAppleEventDescriptor listDescriptor];
+ unsigned int idx = 1;
+ for (id obj in (NSArray *)self) [desc insertDescriptor:[obj ASDescriptor] atIndex:idx++];
+ }
else if ([self respondsToSelector:@selector(objectSpecifier)])
desc = [[self objectSpecifier] _asDescriptor];
else

0 comments on commit 1843c86

Please sign in to comment.