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 if(OSX_VERSION < 100700)
16 [NSAutoreleasePool new];
18 [NSApplication sharedApplication];
19 NSObject<NSApplicationDelegate> *delegate = [appdelegate new];
20 [NSApp setDelegate:delegate];
22 NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; /* Register a call-back for URL Events */
23 [appleEventManager setEventHandler:delegate andSelector:@selector(handleGetURLEvent:withReplyEvent:)
24 forEventClass:kInternetEventClass andEventID:kAEGetURL];
26 [NSApp run];
27 }
29 @implementation appdelegate
30 - (void)application:(id)arg openFiles:(NSArray*)file
31 {
32 int i,n;
33 NSString *s;
35 n = [file count];
36 for(i=0; i<n; i++){
37 s = [file objectAtIndex:i];
38 print("%s\n", [s UTF8String]);
39 }
40 [NSApp terminate:self];
41 }
43 - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
44 {
45 NSString* url = [[event descriptorForKeyword:keyDirectObject] stringValue];
46 print("%s\n", [url UTF8String] + (sizeof("plumb:") - 1));
47 [NSApp terminate:self];
48 }
49 @end