Skip to content

Instantly share code, notes, and snippets.

@fousa
Created July 16, 2012 19:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fousa/3124478 to your computer and use it in GitHub Desktop.
Save fousa/3124478 to your computer and use it in GitHub Desktop.
NSService
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSApp setServicesProvider:[MyService new]];
...
@interface MyService : NSObject
@end
@implementation MyService
- (void)processService:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error {
NSArray *classes = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];
if (![pboard canReadObjectForClasses:classes options:options]) {
*error = NSLocalizedString(@"Error: couldn't encrypt text.", @"pboard couldn't give string.");
return;
}
// Handle your content
[pboard clearContents];
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Archive with My Application...</string>
</dict>
<key>NSMessage</key>
<string>processService</string>
<key>NSPortName</key>
<string>MyService</string>
<key>NSRequiredContext</key>
<array/>
<key>NSSendFileTypes</key>
<array>
<string>public.item</string>
</array>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
<key>NSServiceDescription</key>
<string>Process your files with My Application</string>
</dict>
</array>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment