Reputation: 3031
Here is the code:
- (IBAction) charlieImputText:(id)sender {
NSAppleScript *keystrokeReturn = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to keystroke return"];
[keystrokeReturn executeAndReturnError:nil];
[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 what this does is it sends what's ever in the text field to terminal and displays terminal's response on a text label. However, this does not work the way I want it to. It does not send the user input to terminal. Any ideas?
Upvotes: 0
Views: 273
Reputation: 237110
You need to quote the argument to do shell script
. Also, this depends on there being a directory at the path /Applications/jarvis/scripts
, which is kind of odd though not impossible.
Upvotes: 1
Reputation: 13972
First: Does charlieImputSelf the value you expect?
Second: try passing an NSError into your [sendCharlieImput executeAndReturnError:nil];
Do something like:
NSAppleEventDescriptor * ourRes = [theScript executeAndReturnError: &errorDict];
if (ourRes == nil)
{
// error...
[NSApp activateIgnoringOtherApps: YES];
showNSAlert( @"AppleScript error", [errorDict valueForKey:NSAppleScriptErrorMessage]);
}
(I'll leave you to provide the implementation of showNSAlert, or just use NSLog here...)
Upvotes: 0