-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickSnippetsPaste.m
57 lines (46 loc) · 1.58 KB
/
QuickSnippetsPaste.m
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
50
51
52
53
54
55
56
57
//
// QuickSnippetsPaste.m
// QuickSnippets
//
// Created by Taichiro Yoshida on 09/11/06.
// Copyright Taichiro Yoshida 2009. All rights reserved.
//
#import <Vermilion/Vermilion.h>
@interface QuickSnippetsPaste : HGSAction
@end
@implementation QuickSnippetsPaste
- (BOOL)performWithInfo:(NSDictionary*)info {
HGSLogDebug(@"QuickSnippetsPaste:performWithInfo");
HGSResultArray *directObjects = [info objectForKey:kHGSActionDirectObjectsKey];
BOOL success = NO;
if ([directObjects count] == 1) {
CGEventSourceRef eventSourceRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
if (!eventSourceRef) {
HGSLog(@"cannot get CGEventSourceRef");
success = NO;
} else {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
NSString *name = [directObjects displayName];
[pasteboard setString:name forType:NSStringPboardType];
CGKeyCode vKey = 9;
CGEventRef vKeyDown = CGEventCreateKeyboardEvent(eventSourceRef, vKey, true);
CGEventRef vKeyUp = CGEventCreateKeyboardEvent(eventSourceRef, vKey, false);
CGEventSetFlags(vKeyDown, kCGEventFlagMaskCommand);
CGEventPost(kCGSessionEventTap, vKeyDown);
CGEventPost(kCGSessionEventTap, vKeyUp);
CFRelease(vKeyDown);
CFRelease(vKeyUp);
CFRelease(eventSourceRef);
success = YES;
}
}
return success;
}
- (BOOL)appliesToResult:(HGSResult *)result {
return NO;
}
- (BOOL)appliesToResults:(HGSResultArray *)results {
return NO;
}
@end