Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > my service can't get the contents of the pasteboard

my service can't get the contents of the pasteboard
Thread Tools
siemsen
Fresh-Faced Recruit
Join Date: Feb 2010
Status: Offline
Reply With Quote
Feb 11, 2010, 04:06 AM
 
I'm trying to make an app work as a service in Snow Leopard. I think I've followed the instructions in the Apple Service Implementation Guide, and it *almost* works. I can fire up TextEdit, type some text, highlight it with the mouse, and invoke my app via either the TextEdit->Services menu or a key sequence. My app gets launched and the proper instance method gets called. The problem is that the method can't get the contents of the pasteboard.

The relevant code fragment, mostly stolen from the Guide, follows. I added a several debugging lines, but they haven't enlightened me.

Code:
- (void)lookupTerm:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error { NSLog(@"lookupTerm: called (Cool!)\n"); // Test for strings on the pasteboard. NSArray *classes = [NSArray arrayWithObject:[NSString class]]; NSDictionary *options = [NSDictionary dictionary]; NSString *pname = [pboard name]; NSLog(@"lookupTerm: pname = \"%@\"\n", pname); NSArray *parray = [pboard pasteboardItems]; NSLog(@"lookupTerm: parray count = %d\n", [parray count]); NSLog(@"lookupTerm: classes count = %d\n", [classes count]); NSLog(@"lookupTerm: options count = %d\n", [options count]); NSLog(@"lookupTerm: classes[0] = %@%\n", classes[0]); if (![pboard canReadObjectForClasses:classes options:options]) { *error = NSLocalizedString(@"Error: lookupTerm couldn't lookup text.", @"couldn't get string from pasteboard"); NSLog(@"lookupTerm: couldn't get string from pasteboard\n"); return; } <more code here>
When I test it as described above, this appears in my Console:


lookupTerm: called (Cool!)
lookupTerm: pname = "CFPasteboardUnique-22474b5480df"
lookupTerm: parray count = 0
lookupTerm: classes count = 1
lookupTerm: options count = 0
lookupTerm: classes[0] = NSCFArray
lookupTerm: couldn't get string from pasteboard

FWIW, here's the relevant part of my Info.plist file:

Code:
<key>NSServices</key> <array> <dict> <key>NSMessage</key> <string>lookupTerm</string> <key>NSPortName</key> <string>PetesLookup</string> <key>NSKeyEquivalent</key> <dict> <key>Key equivalent (with command and shift)</key> <string>7</string> </dict> <key>NSMenuItem</key> <dict> <key>default</key> <string>Pete's lookup</string> </dict> </dict> </array>
The "Testing" section of the Apple Services Implementation Guide suggests using NSDebugServices, so I did, and invoked my service, and I saw:

Code:
$ /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices edu.ucar.PetesLookup 2010-02-09 14:05:29.588 TextEdit[26940:903] NSDebugServices=edu.ucar.PetesLookup Pete's lookup (edu.ucar.PetesLookup) is explicitly enabled in the services menu and enabled in the context menu, in preferences. Pete's lookup (edu.ucar.PetesLookup) has a custom key equivalent: &lt;NSKeyboardShortcut: 0x1004e0a10 (??7)&gt;. Pete's lookup (edu.ucar.PetesLookup) is explicitly enabled in the services menu and enabled in the context menu, in preferences. Pete's lookup (edu.ucar.PetesLookup) has a custom key equivalent: &lt;NSKeyboardShortcut: 0x115111270 (??7)&gt;. Pete's lookup (edu.ucar.PetesLookup) has been approved by default, as it does not contain any required context. $
The first 3 lines were output when TextEdit started. The last 3 lines appeared when I highlighted some text in TextEdit and hit Shift-Command-7. It all seems good to me, but my app still can't get the contents of the pasteboard.

I'm not sure how to debug this further. Help!

-- Pete
     
msuper69
Professional Poster
Join Date: Jan 2000
Location: Columbus, OH
Status: Offline
Reply With Quote
Feb 11, 2010, 11:29 AM
 
Mods, please move this thread to the appropriate forum: Developer Center - MacNN Forums

OP: You might also try: Apple Developer Connection - Mac Dev Center
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:22 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,