2015-10-27 23 views
0

我正在製作一個Finder插件,但是當我詢問所選文件時,該方法最多隻能給我10個項目。爲什麼[FIFinderSyncController defaultController] .selectedItemURLs只給我最多10個項目?

[FIFinderSyncController defaultController] .selectedItemURLs

更新: 我把它解決了一半...... 我使用ScriptingBridge訪問Finder和獲得最前面的窗口中選定的項目。 (沙箱需要:com.apple.security.temporary-exception.apple-events)。 奇怪的是,即使您的應用程序菜單正在「烹飪」其項目以顯示,短時間後上下文菜單也會出現。無論如何,您的物品都會在您完成創建後出現。 唯一的問題是,如果在Finder窗口內有上下文菜單或模態對象,ScriptingBridge將不會執行。只有在您解散菜單時纔會結束執行。 我只能使用FIFinderSyncController獲取menuForMenuKind中的選定項目,但在使用ScriptingBridge觸發菜單操作後,我可以獲取所有項目。 對於我的應用程序來說,在顯示相應操作的菜單之前知道我選擇了哪些項目很重要,但現在我必須對此解決方案感到滿意。

+0

您期望有多少物品 回? – Eric

+0

我希望獲得我在Finder中選擇的項目數。 它的工作原理,但如果我選擇了超過10個項目,它只是說我已經選擇了10個,而不是更多。似乎是蘋果的某種限制。我不知道。 –

+0

我正在使用'selectedItemURLs',可以生成甚至1000個項目的選擇。請顯示你的代碼,你必須做一些其他的錯誤。 – Mugen

回答

0

對於下面的代碼:

- (NSMenu *)menuForMenuKind:(FIMenuKind)whichMenu 
{ 
    NSArray *selectedPaths = [self getSelectedItems]; 
    // ... 
    return ... 
} 

- (NSArray *)getSelectedItems 
{ 
    NSMutableArray *selectedItems = [[NSMutableArray alloc] init]; 
    for (NSURL *selectedItemURL in [[FIFinderSyncController defaultController] selectedItemURLs]) { 
     [selectedItems addObject:selectedItemURL.path]; 
     NSLog(@"FinderSync selected item at path '%@'", selectedItemURL.path); 
    } 
    return selectedItems; 
} 

而對於以下目錄:

11 Files

在目錄中選擇所有文件,並打開上下文菜單時,我發現了以下輸出:

11/11/15 7:52:24.432 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/1.txt' 
11/11/15 7:52:24.432 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/2.txt' 
11/11/15 7:52:24.432 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/3.txt' 
11/11/15 7:52:24.432 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/4.txt' 
11/11/15 7:52:24.433 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/5.txt' 
11/11/15 7:52:24.433 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/6.txt' 
11/11/15 7:52:24.433 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/7.txt' 
11/11/15 7:52:24.433 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/8.txt' 
11/11/15 7:52:24.433 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/9.txt' 
11/11/15 7:52:24.434 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/10.txt' 
11/11/15 7:52:24.434 AM MyFinderSync[28375]: FinderSync selected item at path '/Users/Mugen/Workspace/11 Files/11.txt' 
相關問題