本文介绍了启动 Finder 窗口并选择特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Xcode 项目以编程方式启动 OS X Finder 窗口.我需要打开特定文件夹的窗口并自动选择该文件夹中的特定文件.

I'm trying to programmatically launch an OS X Finder window from an Xcode project. I need the window to open to a specific folder and have specific files within that folder automatically selected.

这类似于在 Finder 中显示";Xcode 和相关应用中使用的功能.

This is similar to the "Show in Finder" functionality used in Xcode and related apps.

有人知道如何在 Objective-C、Swift、AppleScript 或 Finder 命令行参数中执行此操作吗?

Does anyone know how to do this in either Objective-C, Swift, AppleScript, or Finder command-line parameters?

推荐答案

Objective-C 版本:

Objective-C version:

NSArray *fileURLs = [NSArray arrayWithObjects:fileURL1, /* ... */ nil];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];

这篇关于启动 Finder 窗口并选择特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 18:15