0

我正在制作一个 Finder 插件,但是当我要求选择的文件时,该方法最多只能给我 10 个项目。

[FIFinderSyncController defaultController].selectedItemURLs

更新:我解决了一半......我正在使用 ScriptingBridge 访问 Finder 并获取最前面窗口的选定项目。(沙盒需要:com.apple.security.temporary-exception.apple-events)。奇怪的是,即使您的应用程序菜单正在“烹饪”要显示的项目,上下文菜单也会在短时间内出现。无论如何,您的项目都会在您完成创建后出现。唯一的问题是如果 Finder 窗口中有上下文菜单或模式对象,ScriptingBridge 将不会执行。只有当您关闭菜单时,它才会完成执行。我只能使用 FIFinderSyncController 获取 menuForMenuKind 中的选定项目,但我可以在使用 ScriptingBridge 触发菜单操作后获取所有项目。

4

1 回答 1

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 个文件

选择目录中的所有文件并打开上下文菜单时,我得到以下输出:

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'
于 2015-11-11T06:38:45.703 回答