我最近一直在尝试让 NSServices 为我的应用程序工作,但没有成功。我已经根据文档进行了设置,但它没有出现在服务菜单中(但是它确实作为服务菜单项出现在系统偏好设置的键盘快捷键部分中) 无论如何,我在我的应用程序 Controller 中设置服务如下:
[NSApp setServicesProvider:self];
暴露的方法是:
- (void) addDownloadService:(NSPasteboard *)pboard
userData:(NSString *)userData error:(NSString **)error
我的 Info.plist 看起来像这样:
<key>NSServices</key>
<array>
<dict>
<key>NSReturnTypes</key>
<array>
<string></string>
</array>
<key>NSKeyEquivalent</key>
<dict>
<key>English</key>
<string>S</string>
<key>Key equivalent (with command and shift)</key>
<string>S</string>
</dict>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
<string>NSURLPboardType</string>
<string>NSRTFPboardType</string>
</array>
<key>NSPortName</key>
<string>MyApp</string>
<key>NSMessage</key>
<string>addDownloadService</string>
<key>NSMenuItem</key>
<dict>
<key>English</key>
<string>MyNewService</string>
<key>default</key>
<string> MyNewService </string>
</dict>
</dict>
</array>
我尝试使用 textedit 运行调试命令,如下所示: /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices com.companyname.MyApp
输出以下内容: 根据标准服务策略,MyNewService (com.companyname.MyApp) 在服务菜单中被禁用,并且在上下文菜单中被禁用。
有人知道为什么它可能不起作用吗?
谢谢 科林
最佳答案
我刚刚遇到了同样的问题。 Snow Leopard 似乎默认禁用了第三方服务。
您必须打开“首选项”>“键盘”,选择第二个选项卡(很快,我现在不记得了)选择“服务”,查找您的服务,然后激活它。
据我所知,没有其他解决方法。
关于cocoa - NSServices 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1370616/