Skip to content
Newer
Older
100644 74 lines (47 sloc) 1.66 KB
5f07b80 @ccgus Automator stuff.
authored
1 //
2 // automator.m
3 // automator
4 //
5 // Created by August Mueller on 3/5/09.
6 // Copyright 2009 Flying Meat Inc. All rights reserved.
7 //
8
9 #import "JSTAutomator.h"
10 #import <JSTalk/JSTalk.h>
11
12 @implementation JSTAutomator
13
4a466d8 @ccgus 64bit stuff, make sure everything builds, 10.7 minimum right now.
authored
14 - (void)setupJSTalkEnv:(JSTalk *)jstalk {
15 /*
2310230 Automator goodness.
August Mueller authored
16 JSCocoaController *jsController = [jstalk jsController];
17 jsController.delegate = self;
4a466d8 @ccgus 64bit stuff, make sure everything builds, 10.7 minimum right now.
authored
18 */
19
20 [jstalk setErrorController:self];
21 [jstalk setPrintController:self];
2310230 Automator goodness.
August Mueller authored
22
23 }
24
25 - (void) print:(NSString*)s {
26 NSLog(@"%@", s);
27 }
5f07b80 @ccgus Automator stuff.
authored
28
29 - (id)runWithInput:(id)input fromAction:(AMAction *)anAction error:(NSDictionary **)errorInfo {
30 // Add your code here, returning the data to be passed to the next action.
31
32 id result = 0x00;
33
34 NSString *script = [[self parameters] objectForKey:@"script"];
35
2310230 Automator goodness.
August Mueller authored
36 NSLog(@"script: %@", script);
37
5f07b80 @ccgus Automator stuff.
authored
38 if (script) {
2310230 Automator goodness.
August Mueller authored
39 JSTalk *jstalk = [[[JSTalk alloc] init] autorelease];
40 [self setupJSTalkEnv:jstalk];
41
42 [jstalk executeString:script];
43 result = [jstalk callFunctionNamed:@"run" withArguments:[NSArray arrayWithObjects:input, [self parameters], nil]];
44
45 NSLog(@"result: %@", result);
46
5f07b80 @ccgus Automator stuff.
authored
47 }
48
49
2310230 Automator goodness.
August Mueller authored
50 return result;
5f07b80 @ccgus Automator stuff.
authored
51 }
52
2310230 Automator goodness.
August Mueller authored
53
4a466d8 @ccgus 64bit stuff, make sure everything builds, 10.7 minimum right now.
authored
54 - (void)JSTalk:(JSTalk*)jstalk hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
2310230 Automator goodness.
August Mueller authored
55
56 lineNumber -= 1;
57
f8724ec @ccgus Fixing a couple more error.
authored
58 NSLog(@"Error on line %ld, %@", lineNumber, error);
2310230 Automator goodness.
August Mueller authored
59
60 }
61
62
5f07b80 @ccgus Automator stuff.
authored
63 - (void) runScript:(id)sender {
64
65 JSTalk *t = [[[JSTalk alloc] init] autorelease];
2310230 Automator goodness.
August Mueller authored
66 [self setupJSTalkEnv:t];
5f07b80 @ccgus Automator stuff.
authored
67 [t executeString:[[scriptView textStorage] string]];
68 id result = [t callFunctionNamed:@"run" withArguments:[NSArray array]];
69 (void) result;
70
71 }
72
73 @end
Something went wrong with that request. Please try again.