Blob


1 #import <Cocoa/Cocoa.h>
2 #import <Foundation/Foundation.h>
4 #include <u.h>
5 #include <libc.h>
7 AUTOFRAMEWORK(Foundation)
8 AUTOFRAMEWORK(Cocoa)
10 @interface appdelegate : NSObject<NSApplicationDelegate> @end
12 void
13 main(void)
14 {
15 [NSApplication sharedApplication];
16 NSObject<NSApplicationDelegate> *delegate = [appdelegate new];
17 [NSApp setDelegate:delegate];
19 NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; /* Register a call-back for URL Events */
20 [appleEventManager setEventHandler:delegate andSelector:@selector(handleGetURLEvent:withReplyEvent:)
21 forEventClass:kInternetEventClass andEventID:kAEGetURL];
23 [NSApp run];
24 }
26 @implementation appdelegate
27 - (void)application:(id)arg openFiles:(NSArray*)file
28 {
29 int i,n;
30 NSString *s;
32 n = [file count];
33 for(i=0; i<n; i++){
34 s = [file objectAtIndex:i];
35 print("%s\n", [s UTF8String]);
36 }
37 [NSApp terminate:self];
38 }
40 - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
41 {
42 NSString* url = [[event descriptorForKeyword:keyDirectObject] stringValue];
43 print("%s\n", [url UTF8String] + (sizeof("plumb:") - 1));
44 [NSApp terminate:self];
45 }
46 @end