I am trying to enable Services which operate on selected Files and Folders
similar to those which can be invoked in Finder.
I have the following based on the Services Implementation Guide
which works, but only for Text etc
+ (void)initialize {
static BOOL initialized = NO;
/* Make sure code only gets executed once. */
if (initialized == YES) return;
initialized = YES;
NSArray *sendTypes = [NSArray arrayWithObject:NSStringPboardType];
[NSApp registerServicesMenuSendTypes:sendTypes returnTypes:nil];
NSLog(@"initialize MyTableView");
}
- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType {
NSLog(@"validRequestorForSendType %@%@", sendType, returnType);
if ([sendType isEqual:NSStringPboardType]) {
return self;
}
return [super validRequestorForSendType:sendType returnType:returnType];
}
How do I implement URL?
The documentation states
Your NSResponder object can register any pasteboard data type, public or proprietary, common or rare. If it handles the public and common types, of course, it has access to more services. For a list of standard pasteboard data types, see NSPasteboard Class Reference.
There seems to be no corresponding pasteboard data type. I have tried NSURL
, NSURL class
NSFilenamesPboardType
partially works, but does not show all the Services Finder does, and seems to belong to (OS X v10.5 and earlier)
Edit Clarification
I have been following the Services Implementation Guide
, which seems to have 3 steps
1.Registering Objects for Services
NSApp registerServicesMenuSendTypes: returnTypes:
2.Validating Services Menu Items
validRequestorForSendType:returnType:
3.Sending Data to the Service
writeSelectionToPasteboard:types:
I have got the first 2 to partially work (although I cannot get the same Menu I see in Finder when a File is selected in particular the Files and Folders
)
The 3rd seems to be the sticking point
This seems to be supported for NSTextView
, but deprecated for NSObject
I am really looking for some idea how to use Services for Files and Folders
in the same way many other applications do.