【发布时间】:2011-10-28 20:36:41
【问题描述】:
我正在开发一个需要能够将字符串变量从Applescript传递到Objective C的应用程序。我已经弄清楚如何从我的 Objective C 类中的方法运行 Applescript,但我需要能够将 NSString 设置为来自 Applescript 的字符串。我怎样才能做到这一点?
提前致谢!
【问题讨论】:
标签: objective-c cocoa applescript
我正在开发一个需要能够将字符串变量从Applescript传递到Objective C的应用程序。我已经弄清楚如何从我的 Objective C 类中的方法运行 Applescript,但我需要能够将 NSString 设置为来自 Applescript 的字符串。我怎样才能做到这一点?
提前致谢!
【问题讨论】:
标签: objective-c cocoa applescript
快速示例:
NSString *theScript = @"set theTimeString to time string of (current date)\n"
"return theTimeString";
NSDictionary *errorInfo = nil;
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:theScript];
NSAppleEventDescriptor *theDescriptor = [run executeAndReturnError:&errorInfo];
NSString *theResult = [theDescriptor stringValue];
NSLog(@"%@",theResult);
输出:
下午 2:36:06
【讨论】:
查看 NSAppleEventDescriptor 的文档,尤其是方法 -[NSAppleEventDescriptor stringValue]
【讨论】: