【问题标题】:How Can I Pass a String From Applescript to Objective C如何将字符串从 Applescript 传递到 Objective C
【发布时间】:2011-10-28 20:36:41
【问题描述】:

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

提前致谢!

【问题讨论】:

    标签: objective-c cocoa applescript


    【解决方案1】:

    快速示例:

    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

    【讨论】:

      【解决方案2】:

      查看 NSAppleEventDescriptor 的文档,尤其是方法 -[NSAppleEventDescriptor stringValue]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-12
        • 1970-01-01
        • 2014-02-24
        • 1970-01-01
        • 2011-09-09
        • 1970-01-01
        相关资源
        最近更新 更多