在Finder中获取所选文件的路径 [英] Get Path to selected file in Finder

查看:275
本文介绍了在Finder中获取所选文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检索Finder中选定文件的路径数组?

How would I retrieve an array of paths to the selected files in Finder?

我已经搜索过,但只找到了关于AppleScript的链接。我也看过 NSWorkspace NSFileManager 但我没有找到任何东西。

I have searched around but have only found links regarding AppleScript. I have also looked at NSWorkspace and NSFileManager but I didn't find anything.

推荐答案

如果可以使用AppleScript在给定的Finder窗口中获取所选文件的列表,则可以使用脚本桥在Cocoa应用程序中与Finder交互。引用Apple的文档

If it is possible to get the list of selected files in a given Finder window using AppleScript, you can probably use Scripting Bridge in a Cocoa application to interface with Finder. Quoting Apple’s documentation,


Scripting Bridge是一个框架和一种技术,使Cocoa开发人员能够更轻松地控制和编写脚本应用程序。不要在应用程序中包含AppleScript脚本或处理发送和处理Apple事件的复杂性,您可以简单地将Objective-C消息发送到代表具有脚本接口的应用程序的对象。您的Cocoa应用程序可以执行任何AppleScript脚本可以做的事,但它在与您的项目代码的其余部分集成的Objective-C代码中执行。

Scripting Bridge is a framework and a technology that makes it much easier for Cocoa developers to control and communicate with scriptable applications. Instead of incorporating AppleScript scripts in your application or dealing with the complexities of sending and handling Apple events, you can simply send Objective-C messages to an object that represents an application with a scripting interface. Your Cocoa application can do anything an AppleScript script can, but it does so in Objective-C code that is integrated with the rest of your project’s code.

没有Cocoa类表示Finder,或更具体地,Finder窗口。 Finder是一个应用程序,是一个可编写脚本的应用程序,所以脚本桥是要走的路。

There is no Cocoa class that represents Finder or, more specifically, Finder windows. Finder is an application, and a scriptable application at that, so Scripting Bridge is the way to go.

这篇关于在Finder中获取所选文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆