forked from fyhuang/enjoy2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTargetScript.m
54 lines (43 loc) · 1.2 KB
/
TargetScript.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
//
// TargetScript.m
// Enjoy2
//
// Created by Aaron Schain on 11/18/17.
//
#import "TargetScript.h"
@implementation TargetScript
@synthesize scriptPath;
-(NSString*) stringify {
return [[NSString alloc] initWithFormat: @"scpt~%@", scriptPath];
}
+(TargetScript*) unstringifyImpl: (NSArray*) comps {
NSParameterAssert([comps count] == 2);
TargetScript* target = [[TargetScript alloc] init];
[target setScriptPath: (NSString*)[comps objectAtIndex:1]];
return target;
}
-(void) trigger: (JoystickController *)jc {
[self runScript];
}
-(void) untrigger: (JoystickController *)jc {
}
-(void) runScript
{
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/sh"];
NSArray *arguments= [NSArray arrayWithObjects:scriptPath, nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"script returned:\n%@", string);
}
@end