views:

54

answers:

1

Here is the code:

- (IBAction) charlieImputText:(id)sender {

[progressBarText startAnimation:self];

charlieImputSelf = [sender stringValue];

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Terminal\" to do shell script  \"%@\"", charlieImputSelf]];
[sendCharlieImput executeAndReturnError:nil];                   

NSDictionary* errorDict;
NSAppleScript* script=[[NSAppleScript alloc] 
                       initWithContentsOfURL:[NSURL fileURLWithPath:@"/applications/jarvis/scripts/getTextCharlieResponce.scpt" ]
                       error:&errorDict];
NSAppleEventDescriptor* desc=[script executeAndReturnError:&errorDict];
NSString* result=[desc stringValue];
self.charlieOutput.stringValue = result;
charlieOutput.textColor = [NSColor greenColor];
[script release];

[progressBarText stopAnimation:self];

 }

Ok, this still doesn't work the way I want it to. It doesn't send what's in the text field to the terminal.

Any ideas??

Elijah

+1  A: 

You are expecting that when you send "do shell script" to the Terminal that the command and its output will be shown in the Terminal window. That's an invalid assumption; you can test it by trying it directly from Script Editor.

do shell script is a scripting addition that works in the background in any application. Terminal doesn't handle it specially.

You want do script intead. Note that if anything other than the most simple and clean one-liner is entered in the text field, the NSStringWithFormat will probably create an invalid piece of AppleScript and fail. You should do some error-checking at least, or try a different approach.

But you're going to have to tell us the contents of /applications/jarvis/scripts/getTextCharlieResponce.scpt as well, and if the desc ends up nil, it would be good to know what's in the error result.

And you should release the sendCharlieImput.

cdespinosa