如何将字符串从 Applescript 传递到 Objective C [英] How Can I Pass a String From Applescript to Objective C

查看:33
本文介绍了如何将字符串从 Applescript 传递到 Objective C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我需要能够将字符串变量从 Applescript 传递到 Objective C.我已经想出了如何从我的 Objective C 类中的方法运行 Applescript,但我需要能够将 NSString 设置为 Applescript 中的字符串.我如何才能做到这一点?

I'm working on an application where I need to be able to pass a string variable from Applescript to Objective C. I have figured out how to run Applescript from a method in my Objective C Class, but I need to be able to set an NSString to a string from Applescript. How would I be able to accomplish this?

提前致谢!

推荐答案

快速示例:

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

这篇关于如何将字符串从 Applescript 传递到 Objective C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆