-
Notifications
You must be signed in to change notification settings - Fork 28
/
JSTAutomator.m
70 lines (45 loc) · 1.64 KB
/
JSTAutomator.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
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// automator.m
// automator
//
// Created by August Mueller on 3/5/09.
// Copyright 2009 Flying Meat Inc. All rights reserved.
//
#import "JSTAutomator.h"
#import <JSTalk/JSTalk.h>
#import <JSTalk/JSCocoa.h>
@implementation JSTAutomator
- (void) setupJSTalkEnv:(JSTalk *)jstalk {
JSCocoaController *jsController = [jstalk jsController];
jsController.delegate = self;
jstalk.printController = self;
}
- (void) print:(NSString*)s {
NSLog(@"%@", s);
}
- (id)runWithInput:(id)input fromAction:(AMAction *)anAction error:(NSDictionary **)errorInfo {
// Add your code here, returning the data to be passed to the next action.
id result = 0x00;
NSString *script = [[self parameters] objectForKey:@"script"];
NSLog(@"script: %@", script);
if (script) {
JSTalk *jstalk = [[[JSTalk alloc] init] autorelease];
[self setupJSTalkEnv:jstalk];
[jstalk executeString:script];
result = [jstalk callFunctionNamed:@"run" withArguments:[NSArray arrayWithObjects:input, [self parameters], nil]];
NSLog(@"result: %@", result);
}
return result;
}
- (void) JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
lineNumber -= 1;
NSLog(@"Error on line %ld, %@", lineNumber, error);
}
- (void) runScript:(id)sender {
JSTalk *t = [[[JSTalk alloc] init] autorelease];
[self setupJSTalkEnv:t];
[t executeString:[[scriptView textStorage] string]];
id result = [t callFunctionNamed:@"run" withArguments:[NSArray array]];
(void) result;
}
@end