Created
July 16, 2012 19:19
-
-
Save fousa/3124478 to your computer and use it in GitHub Desktop.
NSService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation AppDelegate | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
[NSApp setServicesProvider:[MyService new]]; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface MyService : NSObject | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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