2011-12-22 9 views
1

私は、mach_injectでプラグインを作成してFinderのコンテキストメニューに項目を追加しています。 NSMenuをフックすることで正常に追加できました。しかし、今私は右クリックされたアイテムを取得する必要があります。 誰かが次のコードを使用できると言っていましたが、右クリックしたアイテムの代わりに選択したアイテムのみを取得できます(Finderでは、アイテムを1つ選択して右クリックした場合、変更されません)。誰でもFinderでアイテムを右クリックする方法を知っていますか?ありがとう!OSX上のFinderでファイル項目を右クリックする方法

SBElementArray * selection = [[finder selection] get]; 

NSArray * items = [selection arrayByApplyingSelector:@selector(URL)]; 
for (NSString * item in items) { 
    NSURL * url = [NSURL URLWithString:item]; 
    NSLog(@"selected item url: %@", url); 
} 
+0

1のようなファイルを取得することができ、また、私はこのことを知っていただきたいと思います。 – livingtech

答えて

2

選択したファイルを取得し、あなたはいくつかの助けコード

struct TFENode { 
struct OpaqueNodeRef *fNodeRef; 
}; 

struct TFENodeVector { 
    struct TFENode *_begin; 
    struct TFENode *_end; 
    struct TFENode *_end_cap; 
}; 

- (NSArray *)arrayForNodeVector:(const struct TFENodeVector *)vector 
{ 
    NSInteger capacity = vector->_end - vector->_begin; 
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:capacity]; 
    struct TFENode *node; 
    for (node = vector->_begin; node < vector->_end; ++node) { 
     [array addObject: [self pathForNode:node]]; 
    } 
    return array; 
} 

を準備する必要があります前に、あなたはこの

// Snow Leopard & Lion 
// gNodeHelper is where you put above code 
// override_handleContextMenuCommon: is your override function 

+ (void)override_handleContextMenuCommon:(unsigned int)context 
            nodes:(const struct TFENodeVector *)nodes 
            event:(id)event 
            view:(id)view 
         windowController:(id)windowController 
           addPlugIns:(BOOL)flag 
{ 
    NSArray *paths = [gNodeHelper arrayForNodeVector:nodes]; 

    [self override_handleContextMenuCommon:context 
            nodes:nodes 
            event:event 
            view:view 
         windowController:windowController 
           addPlugIns:flag]; 

} 
関連する問題