tangled
alpha
login
or
join now
jcs.org
/
adium-pipeevent
0
fork
atom
Adium plugin to pipe events/messages to an external program
0
fork
atom
overview
issues
pulls
pipelines
xcode's editor is sloppy
set tabs to 8
jcs.org
15 years ago
8da48b5a
3584ef52
+23
-24
2 changed files
expand all
collapse all
unified
split
PipeEventPlugin.h
PipeEventPlugin.m
+1
-1
PipeEventPlugin.h
···
3
3
#import <Adium/AISharedAdium.h>
4
4
#import <Adium/AIContactAlertsControllerProtocol.h>
5
5
6
6
-
#define KEY_COMMAND @"PipeEvent"
6
6
+
#define KEY_COMMAND @"PipeEvent"
7
7
8
8
@protocol AIContentFilter;
9
9
+22
-23
PipeEventPlugin.m
···
5
5
#import <Adium/AIListContact.h>
6
6
7
7
#define PIPE_EVENT_IDENTIFIER @"PipeEvent"
8
8
-
#define PIPE_EVENT_SHORT @"Pipe event to command"
8
8
+
#define PIPE_EVENT_SHORT @"Pipe event to command"
9
9
#define PIPE_EVENT_LONG @"Pipe event to \"%@\""
10
10
11
11
@implementation PipeEventPlugin
···
23
23
24
24
/* subtext for the "When you receive any message" line, and the text in the full events list */
25
25
- (NSString *)longDescriptionForActionID:(NSString *)actionID
26
26
-
withDetails:(NSDictionary *)details
26
26
+
withDetails:(NSDictionary *)details
27
27
{
28
28
-
NSString *command = [details objectForKey:KEY_COMMAND];
28
28
+
NSString *command = [details objectForKey:KEY_COMMAND];
29
29
30
30
-
if (command && [command length]) {
31
31
-
return [NSString stringWithFormat:PIPE_EVENT_LONG, [command lastPathComponent]];
32
32
-
} else {
33
33
-
return PIPE_EVENT_SHORT;
34
34
-
}
30
30
+
if (command && [command length])
31
31
+
return [NSString stringWithFormat:PIPE_EVENT_LONG, [command lastPathComponent]];
32
32
+
else
33
33
+
return PIPE_EVENT_SHORT;
35
34
}
36
35
37
36
- (NSImage *)imageForActionID:(NSString *)actionID
···
47
46
/* the actual event handler */
48
47
- (BOOL)performActionID:(NSString *)actionID
49
48
forListObject:(AIListObject *)listObject
50
50
-
withDetails:(NSDictionary *)details
51
51
-
triggeringEventID:(NSString *)eventID
52
52
-
userInfo:(id)userInfo
49
49
+
withDetails:(NSDictionary *)details
50
50
+
triggeringEventID:(NSString *)eventID
51
51
+
userInfo:(id)userInfo
53
52
{
54
53
NSString *command = [details objectForKey:KEY_COMMAND];
55
54
NSString *message = [adium.contactAlertsController naturalLanguageDescriptionForEventID:eventID
56
56
-
listObject:listObject
57
57
-
userInfo:userInfo
58
58
-
includeSubject:NO];
55
55
+
listObject:listObject
56
56
+
userInfo:userInfo
57
57
+
includeSubject:NO];
59
58
NSString *sender;
60
59
AIChat *chat = nil;
61
61
-
60
60
+
62
61
NSTask *task = [[NSTask alloc] init];
63
63
-
62
62
+
64
63
[task setLaunchPath:command];
65
64
66
65
// for a message event, listObject should become whoever sent the message
···
70
69
AIContentObject *contentObject = [userInfo objectForKey:@"AIContentObject"];
71
70
AIListObject *source = [contentObject source];
72
71
chat = [userInfo objectForKey:@"AIChat"];
73
73
-
72
72
+
74
73
if (source)
75
74
listObject = source;
76
75
}
77
77
-
76
76
+
78
77
if (listObject) {
79
78
if ([listObject isKindOfClass:[AIListContact class]]) {
80
79
// use the parent
···
84
83
sender = listObject.displayName;
85
84
} else if (chat)
86
85
sender = chat.displayName;
87
87
-
86
86
+
88
87
// pass the sender (or whatever the event sends) as the first arg
89
88
if (sender)
90
89
[task setArguments:[NSArray arrayWithObjects:sender, nil]];
91
91
-
90
90
+
92
91
// stdout and stderr will be closed right away
93
92
[task setStandardOutput:[NSPipe pipe]];
94
93
[task setStandardError:[NSPipe pipe]];
···
100
99
// close command's stdout and stderr
101
100
[[[task standardOutput] fileHandleForReading] closeFile];
102
101
[[[task standardError] fileHandleForReading] closeFile];
103
103
-
102
102
+
104
103
// send the message contents (with newline) and then close the filehandle
105
104
[[[task standardInput] fileHandleForWriting] writeData:[[NSString stringWithFormat:@"%@\n", message] dataUsingEncoding:NSASCIIStringEncoding]];
106
105
[[[task standardInput] fileHandleForWriting] closeFile];
107
106
108
107
// uh, i guess magic happens here and everything is cleaned up for us
109
109
-
108
108
+
110
109
return YES; // WE CAN
111
110
}
112
111
···
136
135
return @"http://jcs.org/";
137
136
}
138
137
139
139
-
@end
138
138
+
@end