Re: Help to debug NSPerformService..
Re: Help to debug NSPerformService..
- Subject: Re: Help to debug NSPerformService..
- From: Peter Teeson <email@hidden>
- Date: Thu, 09 Jan 2014 15:35:59 -0500
On 2014-01-07, at 11:18 PM, Ken Thomases <email@hidden> wrote:
> On Jan 7, 2014, at 9:57 PM, Peter Teeson wrote:
>> In my app I have this:
>> @interface Guess : NSTextField // populated programmatically
>> …
>> -(void)check; // method to programatically use the Service "Look Up In Dictionary"
>> @end
>> @implementation Guess
>> ...
>> -(void)check { // Lookup word in dictionary
>> // ********** This is my problem
see revised code below
>> BOOL res = NSPerformService(@"Look Up In Dictionary", pasteboard); // debug shows (BOOL) NO
>> }
>> ...
>> @end
>>
>> If I manually select the text in the field by double clicking it, the Services menu is populated and does contain
>> "Look Up In Dictionary".
>
> The slight bit of example code from Apple showing a use of NSPerformService() uses +pasteboardWithUniqueName, not + generalPasteboard. You could try that.
> https://developer.apple.com/library/mac/samplecode/PhotoSearch/Listings/MainWindowController_m.html
> Also, you can try launching your app with "-NSDebugServices com.apple.Dictionary" to see if that's informative.
> That said, perhaps you're actually looking for the -[NSView showDefinitionForAttributedString:…] methods.
> Regards,
> Ken
I revised my code as follows:
-(void)check { // Lookup word in dictionary
[self selectText:nil];
NSString *theString = [self stringValue];
NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName];
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pasteboard setString:theString forType:NSStringPboardType];
NSInteger changeCount = [pasteboard clearContents];
// ********** This is my problem
BOOL res = NSPerformService(@"Look Up In Dictionary", pasteboard);
}
I edited the scheme for Debug to pass this when I run:
-NSDebugServices com.apple.Dictionary
I run my app and create the contents of the TextField then
press a Button whose Target is Guess (my sub-class of NSTextField) and whose Action is the check method:
This is what the Debug Console shows
2014-01-09 15:15:15.333 Garble[7439:303] NSDebugServices=com.apple.Dictionary
Look Up in Dictionary (com.apple.Dictionary) is enabled in the services menu and disabled in the context menu, by the standard Services policy.
Look Up in Dictionary (com.apple.Dictionary) is enabled in the services menu and disabled in the context menu, by the standard Services policy.
But if I manually select the TextField by double clicking and using the Services menu
The Debug Console showed this:
2014-01-09 15:12:32.506 Garble[7427:303] NSDebugServices=com.apple.Dictionary
Look Up in Dictionary (com.apple.Dictionary) is enabled in the services menu and disabled in the context menu, by the standard Services policy.
Look Up in Dictionary (com.apple.Dictionary) is enabled in the services menu and disabled in the context menu, by the standard Services policy.
// This line shows up as soon as I get to the Services menu
Look Up in Dictionary (com.apple.Dictionary) has been approved by default, as it does not contain any required context.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // my emphasis
Double clicking a word in a TextEdit doc and selecting the Services menu produces the same Debug Console output.
So clearly there is something missing from my app. My plist does not have a Required Context as I'm not offering (providing) a service.
Like many others I'm trying to use one - namely Look Up In Dictionary. Except in my case I want to do it from within my app, not manually.
I'm lost as to what is wrong. It works if I select the Service manually but not if I try to do so programmatically.
Thoughts? Suggestions?
TIA
Peter
_______________________________________________
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