简体   繁体   English

可可查找器菜单项仅适用于文件夹

[英]Cocoa finder menu item for folders only

I am trying to create a Finder context menu item using a service (as described here: Writing a Snow Leopard Service for Finder.app ) 我正在尝试使用服务来创建Finder上下文菜单项(如此处所述: 为Finder.app编写Snow Leopard服务

However, I wish to add a context menu entry for folders only. 但是,我只想为文件夹添加一个上下文菜单项。 Whenever I put the following code in my .plist file: 每当我将以下代码放入.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>

Everything works fine, I can select my service in the Services tab (keyborad shourtcuts) and run it. 一切正常,我可以在“服务”选项卡(键盘快捷方式)中选择我的服务并运行它。

However, if I try to use the service for folders: 但是,如果我尝试将服务用于文件夹:

<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>

The service does not appear in the keyboard shortcuts' menu and of course is not visible in finder... 该服务未出现在键盘快捷键的菜单中,并且当然在finder中也不可见。

What am I missing? 我想念什么?

Add the following code to the .plist: 将以下代码添加到.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>

And the service will appear under "Files and Folders" group in the services list (keyboard shortcuts tab). 并且该服务将出现在服务列表(键盘快捷键选项卡)中的“文件和文件夹”组下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM