blob: a0396df39aba24a595a261023810104b9e87117d (
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
|
//
// AppDelegate.m
// Copy Mailto
//
// Created by tw on 9/5/18.
// Copyright © 2018 Teddy Wing
//
#import "AppDelegate.h"
const NSUInteger MAILTO_INDEX = 7;
@implementation AppDelegate
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
[[NSAppleEventManager sharedAppleEventManager]
setEventHandler:self
andSelector:@selector(handleURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
}
- (void)handleURLEvent:(NSAppleEventDescriptor *)event
withReplyEvent: (NSAppleEventDescriptor *)replyEvent
{
NSString *url = [[event paramDescriptorForKeyword:keyDirectObject]
stringValue];
[_email_address setStringValue:[url substringFromIndex:MAILTO_INDEX]];
}
- (IBAction)copyEmailToClipboard:(id)sender
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard writeObjects:
[NSArray arrayWithObject:
[_email_address stringValue]]];
[NSApp terminate:self];
}
@end
|