Пункт меню поиска какао только для папок

Я пытаюсь создать элемент контекстного меню Finder с помощью службы (как описано здесь: Написание сервиса Snow Leopard для 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>

Все работает нормально, я могу выбрать свой сервис на вкладке Services (горячие клавиши) и запустить его.

Однако, если я попытаюсь использовать службу для папок:

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

Служба не отображается в меню сочетаний клавиш и, конечно же, не отображается в поисковике ...

Что мне не хватает?


person Nili    schedule 04.07.2013    source источник


Ответы (1)


Добавьте следующий код в .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>

И сервис появится в группе «Файлы и папки» в списке сервисов (вкладка горячих клавиш).

person Nili    schedule 07.07.2013