无法使用Cocoa中的服务在Finder的上下文菜单中添加项目 [英] Unable to add item in Finder's contextual menu using services in Cocoa

查看:231
本文介绍了无法使用Cocoa中的服务在Finder的上下文菜单中添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我右键点击文件或文件夹时,我想在Finder的上下文菜单中添加一个项目,并且此菜单已链接到我的Cocoa应用程序的方法。

我遵循CocoaDev的例子和Apple的文档,但是我不能得到正在显示的服务。

这是我的.h


I would like to add an item in my Finder's contextual menu whenever I right-click on files or folders, and this menu being linked to a method of my Cocoa app.
I am following CocoaDev's example and Apple's documentation, but I can't get the service being displayed.
Here is my .h

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate,NSObject>

@property (assign) IBOutlet NSWindow *window;
-(void)IClicked:(NSPasteboard *)pboard 
             userData:(NSString *)data
                error:(NSString **)error;

@end

.m

#import "AppDelegate.h"

@implementation AppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [NSApp setServicesProvider:self];
}

- (void)IClicked:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error
{
    NSLog(@"I clicked");
}

@end

-plist.info:

and the extract of my Application-plist.info:

<key>NSServices</key>
<array>
    <dict>
        <key>NSKeyEquivalent</key>
        <dict>
            <key>default</key>
            <string>E</string>
        </dict>
        <key>NSMenuItem</key>
        <dict>
            <key>default</key>
            <string>My Application</string>
        </dict>
        <key>NSMessage</key>
        <string>IClicked</string>
        <key>NSPortName</key>
        <string>TestService</string>
        <key>NSSendFileTypes</key>
        <array>
            <string>public.item</string>
        </array>
        <key>NSSendTypes</key>
        <array>
            <string>NSPasteboardTypeString</string>
        </array>
        <key>NSRequiredContext</key>
        <dict>
            <key>NSServiceCategory</key>
            <string>public.item</string>
        </dict>
        <key>NSReturnTypes</key>
        <array>
            <string>NSPasteboardTypeString</string>
        </array>
    </dict>
</array>
</dict>

我将代码上传到http://www.petits-suisses.ch/TestService.zip

我错了什么,或有任何可用的Cocoa代码我可以下载来理解我做错了什么?


谢谢!

What did I wrong, or is there any available Cocoa code I can download to understand what I did wrong ?

Thanks !

推荐答案



1.我真的不得不将我的应用程序存储到应用程序文件夹中(默认情况下,在使用Xcode编译时不会执行)

2.应该添加< B> NSUpdateDynamicServices(); 在 [NSApp setServicesProvider:self]; 命令之后。

3.启动应用程序后大约等待10秒钟,菜单填充。

Found the issues:
1. I really had to store my application at least once into the Applications folder (which is not done by default when you compile with Xcode)
2. Should have added NSUpdateDynamicServices(); after the [NSApp setServicesProvider:self]; command.
3. Wait roughly 10 secs after having started the app to get Finder's Services menu populated.

这篇关于无法使用Cocoa中的服务在Finder的上下文菜单中添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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