NSServices - my service is being disqualified - why?
NSServices - my service is being disqualified - why?
- Subject: NSServices - my service is being disqualified - why?
- From: Sebastian Pape <email@hidden>
- Date: Fri, 22 Jun 2012 15:47:57 +0200
Hi!
I'm trying to provide a service using NSServices and the service
always becomes disqualified, when trying to debug it. So I have no
chance of ever letting my service fire.
My service should be able to be fired on any string. I assigned a
shortcut to my service in the system preferences (Command-Shift-T). I
read the NSServices guide over and over and always get the same
result. The service is being disqualified, because it's send or return
type cannot be handled by the requestor.
As I don't return anything that shouldn't be the problem. So it must
have something to do with the send types....
My Info.plist contains this:
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Handle string</string>
</dict>
<key>NSMessage</key>
<string>handleString</string>
<key>NSPortName</key>
<string>MyApp</string>
<key>NSRequiredContext</key>
<dict/>
<key>NSSendFileTypes</key>
<array>
<string>NSStringPboardType</string>
<string>public.plain-text</string>
</array>
</dict>
</array>
So, the service should work with any type of string. e.g. TextEdit or
Stickies or even a selected string in Safari...right?
In my app delegate I inserted a method to handle my service requests
and also added the method signature to the .h file.
MyAppDelegate.m
- (void)handleString:(NSPasteboard *)pboard userData:(NSString
*)userData error:(NSString **)error {
NSArray *classes = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];
if (![pboard canReadObjectForClasses:classes options:options]) {
return;
}
NSString *pboardString = [pboard stringForType:NSPasteboardTypeString];
NSLog("NSServices received: %@", pboardString);
}
So, first the service should just log my string to stdout.
If I try to start debugging, the service is always recognized:
user$ /System/Library/CoreServices/pbs -dump_pboard
[…]
{
NSBundleIdentifier = "com.myname.myapp";
NSBundlePath = "/Applications/MyApp.app";
NSKeyEquivalent = {
};
NSMenuItem = {
default = "Handle string";
};
NSMessage = handleString;
NSPortName = MyApp;
NSRequiredContext = {
};
NSSendFileTypes = (
NSStringPboardType,
"public.plain-text"
);
},
[…]
If trying to use the service with Stickies and debugging it the
service is disqualified immediately when using the shortcut
Shift-command-T
user$ /Applications/Stickies.app/Contents/MacOS/Stickies
-NSDebugServices com.myname.myapp
2012-06-22 14:38:33.956 Stickies[12510:903] NSDebugServices=com.myname.myapp
Handle string (com.myname.myapp) is enabled in the services menu and
enabled in the context menu, by the standard Services policy.
Handle string (com.myname.myapp) has a custom key equivalent:
<NSKeyboardShortcut: 0x10052d880 (⇧⌘T)>.
Handle string (com.myname.myapp) is enabled in the services menu and
enabled in the context menu, by the standard Services policy.
Handle string (com.myname.myapp) has a custom key equivalent:
<NSKeyboardShortcut: 0x1005deac0 (⇧⌘T)>.
Handle string (com.myname.myapp) is disqualified because its send
and/or return types cannot be handled by the requestor <NSTextView:
0x1005842b0>
Frame = {{0.00, 0.00}, {290.00, 178.00}}, Bounds = {{0.00, 0.00},
{290.00, 178.00}}
Horizontally resizable: NO, Vertically resizable: YES
MinSize = {290.00, 178.00}, MaxSize = {994.00, 10000000.00}
.
I don't understand why the "NSTextView" can't handle the send type?!
What does that mean for me practically? Do I need to handle the
NSTextView in my method?
Can anybody help me with that?
Thank you
Sebastian!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden