Permalink
Browse files

add a method for retrieving valid iObject types from an AS

  • Loading branch information...
1 parent b903ab9 commit c982b063b0934941f45a7fed8a1379530a92a04b @pjrobertson committed Feb 1, 2013
@@ -13,12 +13,18 @@
# define kAppleScriptOpenFilesAction @"AppleScriptOpenFilesAction"
# define kAppleScriptRunAction @"AppleScriptRunAction"
+// Used as a prefix to the identifier for all AppleScript action objects. Distinguishes them from plain old files
+# define kAppleScriptActionIDPrefix @"[Action]:"
+
+
# define kAppleScriptRunTextAction @"AppleScriptRunTextAction"
#define kQSScriptSuite 'DAED'
#define kQSOpenTextScriptCommand 'opnt'
#define kQSOpenFileScriptCommand 'opfl'
#define kQSGetArgumentCountCommand 'garc'
+#define kQSGetIndirectObjectTypesCommand 'giob'
+#define kQSGetDirectObjectTypesCommand 'gdob'
#define kQSIndirectParameter 'IdOb'
@interface QSAppleScriptActions : QSActionProvider
@@ -43,7 +43,7 @@ - (QSAction *)scriptActionForPath:(NSString *)path {
[actionDict setObject:[NSArray arrayWithObject:QSTextType] forKey:kActionIndirectTypes];
}
NSString *actionName = [[path lastPathComponent] stringByDeletingPathExtension];
- QSAction *action = [QSAction actionWithDictionary:actionDict identifier:[@"[Action]:" stringByAppendingString:path]];
+ QSAction *action = [QSAction actionWithDictionary:actionDict identifier:[kAppleScriptActionIDPrefix stringByAppendingString:path]];
[action setName:actionName];
[action setObject:path forMeta:kQSObjectIconName];
return action;
@@ -262,9 +262,42 @@ - (NSArray *)validIndirectObjectsForAction:(NSString *)action directObject:(QSOb
} else if ([action isEqualToString:kAppleScriptOpenFilesAction]) {
return [QSLib arrayForType:QSFilePathType];
};
+ // Applescript action, so attempt to get the valid types from the file itself
+ if ([action rangeOfString:kAppleScriptActionIDPrefix].location != NSNotFound) {
+ return [self validIndirectObjectsForAppleScript:action directObject:dObject];
+ }
return nil;
}
+-(NSArray *)validIndirectObjectsForAppleScript:(NSString *)script directObject:(QSObject *)dObject {
+ id indirectTypes = nil;
+ // remove the @"[Namne]:" from the start to get the script
+ NSString *scriptPath = [script substringFromIndex:[kAppleScriptActionIDPrefix length]];
+ NSArray *handlers = [NSAppleScript validHandlersFromArray:[NSArray arrayWithObject:@"DAEDgiob"] inScriptFile:scriptPath];
+ if( handlers != nil && [handlers count] != 0 ) {
+ NSAppleEventDescriptor *event;
+ int pid = [[NSProcessInfo processInfo] processIdentifier];
+ NSAppleEventDescriptor* targetAddress = [[NSAppleEventDescriptor alloc] initWithDescriptorType:typeKernelProcessID bytes:&pid length:sizeof(pid)];
+
+ NSDictionary *errorDict = nil;
+ NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] error:&errorDict];
+
+ event = [[NSAppleEventDescriptor alloc] initWithEventClass:kQSScriptSuite eventID:kQSGetIndirectObjectTypesCommand targetDescriptor:targetAddress returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
+
+ NSAppleEventDescriptor *result = [script executeAppleEvent:event error:&errorDict];
+ if( result ) {
+ indirectTypes = (NSInteger)[result int32Value];
+ } else if( errorDict != nil )
+ NSLog(@"error %@", errorDict);
+
+ [event release];
+ [targetAddress release];
+ [script release];
+
+ }
+ return indirectTypes;
+}
+
- (NSInteger)argumentCountForAction:(NSString *)actionId {
NSInteger argumentCount = 1;
QSAction *action = [QSAction actionWithIdentifier:actionId];

0 comments on commit c982b06

Please sign in to comment.