- (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];
}
我是这样的新手,我在另一个问题中发布了此代码的问题,有人回复了我:
你需要引用参数来做shell脚本。
这是什么意思?有人可以展示一个例子吗?
我很抱歉,我不知道这个新时代的术语是什么意思! :d
答案 0 :(得分:0)
在您的代码中,您有:
@"tell application \"Terminal\" to do shell script %@"
%@
是命令“do shell script”的“参数”。所以我想你需要的是:
@"tell application \"Terminal\" to do shell script \"%@\""