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