gpt4 book ai didi

objective-c - 仅适用于文件夹的 Cocoa 查找器菜单项

转载 作者:行者123 更新时间:2023-12-03 17:03:33 25 4
gpt4 key购买 nike

我正在尝试使用服务创建 Finder 上下文菜单项(如下所述:Writing a Snow Leopard Service for Finder.app)

但是,我希望仅为文件夹添加上下文菜单条目。每当我将以下代码放入 .plist 文件中时:

<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Service Handling Demo</string>
</dict>
<key>NSMessage</key>
<string>handleServices</string> <!-- This specifies the selector -->
<key>NSPortName</key>
<string>Tmp</string> <!-- This is the name of the app -->
<key>NSSendTypes</key>
<array>
<string>NSFilenamesPboardType</string>
</array>
</dict>
</array>

一切正常,我可以在“服务”选项卡(键盘快捷键)中选择我的服务并运行它。

但是,如果我尝试使用文件夹服务:

<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Service Handling Demo</string>
</dict>
<key>NSMessage</key>
<string>handleServices</string> <!-- This specifies the selector -->
<key>NSPortName</key>
<string>Tmp</string> <!-- This is the name of the app -->
<key>NSSendFileTypes</key>
<array>
<string>public.directory</string>
</array>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
</dict>
</array>

该服务不会出现在键盘快捷键的菜单中,当然在查找器中也不可见......

我错过了什么?

最佳答案

将以下代码添加到.plist:

<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Folder Handling Demo</string>
</dict>
<key>NSMessage</key>
<string>handleServices</string> <!-- This specifies the selector -->
<key>NSPortName</key>
<string>Tmp</string> <!-- This is the name of the app -->

<!-- Here we're limiting where the service will appear. -->
<key>NSRequiredContext</key>
<dict>
<key>NSTextContent</key>
<string>FilePath</string>
</dict>
<!-- This service is only really useful from the Finder. So
we want the finder only to send us the URI "public.directory"
which *will* include packages (on the off-chance you want to
see the full package directory name) -->
<key>NSSendFileTypes</key>
<array>
<!-- Check out "System-Declared Uniform Type Identifiers"
in the Apple documentation for the various UTI types.
In this example, all we want is a directory, which is
a super-type to other types (e.g. public.folder) -->
<string>public.folder</string>
</array>
</dict>

该服务将出现在服务列表(键盘快捷键选项卡)的“文件和文件夹”组下。

关于objective-c - 仅适用于文件夹的 Cocoa 查找器菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17472270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com