Browse files

Add code to process iObjects that are files for the 'on process' action

Also, fix the setting of the actionDict's Action Handler to ensure the action displays for the correct dObjects (validates objects correctly)
Set file iObjects as pathDescriptors in AppleScript
  • Loading branch information...
1 parent 03e293a commit 7c3de18e7195f4d33e5be090b3a441e03a78900a @pjrobertson committed Aug 14, 2012
View
4 Quicksilver/PlugIns-Main/QSCorePlugIn/Code/QSAppleScriptActions.h
@@ -17,10 +17,12 @@
#define kQSScriptSuite 'DAED'
#define kQSOpenTextScriptCommand 'opnt'
+#define kQSOpenFileScriptCommand 'opfl'
#define kQSGetArgumentCountCommand 'garc'
-#define kQSOpenTextIndirectParameter 'IdOb'
+#define kQSIndirectParameter 'IdOb'
@interface QSAppleScriptActions : QSActionProvider
- (QSObject*)runAppleScript:(NSString *)scriptPath withArguments:(QSObject *)iObject;
+-(NSAppleEventDescriptor *)eventDescriptorForObject:(QSObject *)iObject;
@end
View
55 Quicksilver/PlugIns-Main/QSCorePlugIn/Code/QSAppleScriptActions.m
@@ -23,7 +23,7 @@
@implementation QSAppleScriptActions
- (QSAction *)scriptActionForPath:(NSString *)path {
- NSArray *handlers = [NSAppleScript validHandlersFromArray:[NSArray arrayWithObjects:@"aevtoapp", @"DAEDopnt", @"aevtodoc", nil] inScriptFile:path];
+ NSArray *handlers = [NSAppleScript validHandlersFromArray:[NSArray arrayWithObjects:@"aevtoapp", @"DAEDopnt", @"aevtodoc",@"DAEDopfl", nil] inScriptFile:path];
NSMutableDictionary *actionDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
NSStringFromClass([self class]), kActionClass,
@@ -32,15 +32,16 @@ - (QSAction *)scriptActionForPath:(NSString *)path {
[NSNumber numberWithBool:YES], kActionDisplaysResult,
nil];
- if ([handlers containsObject:@"DAEDopnt"]) {
+ if ([handlers containsObject:@"aevtodoc"] || [handlers containsObject:@"DAEDopfl"]) {
+ [actionDict setObject:[NSArray arrayWithObject:QSFilePathType] forKey:kActionDirectTypes];
+ [actionDict setObject:[handlers containsObject:@"DAEDopfl"] ? @"QSOpenFileWithEventPlaceholder" : @"QSOpenFileEventPlaceholder" forKey:kActionHandler];
+ [actionDict setObject:[NSArray arrayWithObject:QSFilePathType] forKey:kActionIndirectTypes];
+ }
+ if ([handlers containsObject:@"DAEDopnt"] && ![handlers containsObject:@"DAEDopfl"]) {
[actionDict setObject:[NSArray arrayWithObject:QSTextType] forKey:kActionDirectTypes];
[actionDict setObject:@"QSOpenTextEventPlaceholder" forKey:kActionHandler];
[actionDict setObject:[NSArray arrayWithObject:QSTextType] forKey:kActionIndirectTypes];
}
- if ([handlers containsObject:@"aevtodoc"]) {
- [actionDict setObject:[NSArray arrayWithObject:QSFilePathType] forKey:kActionDirectTypes];
- [actionDict setObject:@"QSOpenFileEventPlaceholder" forKey:kActionHandler];
- }
NSString *actionName = [[path lastPathComponent] stringByDeletingPathExtension];
QSAction *action = [QSAction actionWithDictionary:actionDict identifier:[@"[Action]:" stringByAppendingString:path]];
[action setName:actionName];
@@ -140,7 +141,7 @@ - (QSObject*)runAppleScript:(NSString *)scriptPath withArguments:(QSObject *)iOb
} else {
event = [[NSAppleEventDescriptor alloc] initWithEventClass:kQSScriptSuite eventID:kQSOpenTextScriptCommand targetDescriptor:targetAddress returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
[event setParamDescriptor:[NSAppleEventDescriptor descriptorWithString:[iObject stringValue]] forKeyword:keyDirectObject];
- [event setDescriptor:[NSAppleEventDescriptor descriptorWithString:@""] forKeyword:kQSOpenTextIndirectParameter];
+ [event setDescriptor:[NSAppleEventDescriptor descriptorWithString:@""] forKeyword:kQSIndirectParameter];
}
[targetAddress release];
returnDesc = [script executeAppleEvent:event error:&errorInfo];
@@ -166,6 +167,17 @@ - (QSObject *)objectForDescriptor:(NSAppleEventDescriptor *)desc {
return nil;
}
+-(NSAppleEventDescriptor *)eventDescriptorForObject:(QSObject *)object {
+ NSArray *paths = [object validPaths];
+ NSAppleEventDescriptor *objectDescriptor = nil;
+ if ([paths count] > 0) {
+ objectDescriptor = [NSAppleEventDescriptor aliasListDescriptorWithArray:paths];
+ } else {
+ objectDescriptor = [NSAppleEventDescriptor descriptorWithString:[object stringValue]];
+ }
+ return objectDescriptor;
+}
+
- (QSObject *)performAction:(QSAction *)action directObject:(QSObject *)dObject indirectObject:(QSObject *)iObject {
NSDictionary *dict = [action objectForType:QSActionType];
NSString *scriptPath = [dict objectForKey:kActionScript];
@@ -186,31 +198,28 @@ - (QSObject *)performAction:(QSAction *)action directObject:(QSObject *)dObject
NSDictionary *errorDict = nil;
NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] error:&errorDict];
- if ([handler isEqualToString:@"QSOpenFileEventPlaceholder"]) {
+ if ([handler isEqualToString:@"QSOpenFileEventPlaceholder"] || [handler isEqualToString:@"QSOpenFileWithEventPlaceholder"]) {
+ event = [[NSAppleEventDescriptor alloc] initWithEventClass:[handler isEqualToString:@"QSOpenFileEventPlaceholder"] ? kCoreEventClass :kQSScriptSuite
+ eventID:[handler isEqualToString:@"QSOpenFileEventPlaceholder"] ? kAEOpenDocuments : kQSOpenFileScriptCommand
+ targetDescriptor:targetAddress
+ returnID:kAutoGenerateReturnID
+ transactionID:kAnyTransactionID];
NSArray *files = [dObject validPaths];
- event = [[NSAppleEventDescriptor alloc] initWithEventClass:kCoreEventClass eventID:kAEOpenDocuments targetDescriptor:targetAddress returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
[event setParamDescriptor:[NSAppleEventDescriptor aliasListDescriptorWithArray:files] forKeyword:keyDirectObject];
+ if(iObject && ![[iObject primaryType] isEqualToString:QSTextProxyType]) {
+ NSAppleEventDescriptor *iObjectDescriptor = [self eventDescriptorForObject:iObject];
+ [event setDescriptor:iObjectDescriptor forKeyword:kQSIndirectParameter];
+ }
+
} else if ([handler isEqualToString:@"QSOpenTextEventPlaceholder"]) {
event = [[NSAppleEventDescriptor alloc] initWithEventClass:kQSScriptSuite
eventID:kQSOpenTextScriptCommand
targetDescriptor:targetAddress
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
[event setParamDescriptor:[NSAppleEventDescriptor descriptorWithString:[dObject stringValue]] forKeyword:keyDirectObject];
- NSArray *indirectPaths = [iObject validPaths];
- NSAppleEventDescriptor *iObjectDescriptor = nil;
- NSUInteger indirectPathCount = [indirectPaths count];
- if (indirectPathCount == 1) {
- iObjectDescriptor = [NSAppleEventDescriptor descriptorWithString:[indirectPaths objectAtIndex:0]];
- } else if (indirectPathCount > 1) {
- iObjectDescriptor = [NSAppleEventDescriptor listDescriptor];
- for (NSString *path in indirectPaths) {
- [iObjectDescriptor insertDescriptor:[NSAppleEventDescriptor descriptorWithString:path] atIndex:0];
- }
- } else {
- iObjectDescriptor = [NSAppleEventDescriptor descriptorWithString:[iObject stringValue]];
- }
- [event setDescriptor:iObjectDescriptor forKeyword:kQSOpenTextIndirectParameter];
+ NSAppleEventDescriptor *iObjectDescriptor = [self eventDescriptorForObject:iObject];
+ [event setDescriptor:iObjectDescriptor forKeyword:kQSIndirectParameter];
} else {
id object;
NSArray *types = [action directTypes];

0 comments on commit 7c3de18

Please sign in to comment.