【问题标题】:How to transfer the content of an AppleScript variable to an Objective-C action如何将 AppleScript 变量的内容传输到 Objective-C 动作
【发布时间】:2014-01-14 22:36:23
【问题描述】:

我正在尝试了解使用 XCode 5 for OSX Automator 创建的操作。

所以我使用了这样的模板“Automator Action”:

- ( id )runWithInput:( id )input fromAction:( AMAction * )anAction error:( NSDictionary ** )errorInfo
{
    // we expect to receive "Hello World" in the input variable

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
    NSString *desktopDirectory = [paths objectAtIndex:0]; // Get desktop directory
    NSString *logStr = @"";

    logStr = [ NSString stringWithFormat:@"founded %lu", (unsigned long)[input count]];
    [ logStr writeToFile:[ desktopDirectory stringByAppendingPathComponent:@"log.txt" ] atomically:YES encoding:NSUTF8StringEncoding error:nil ];

    return input;        
}

在 Automator 中,我创建了 2 个步骤:

First :执行此操作的 AppleScript 操作:

on run {input, parameters}
    return "Hello World"
end run

如您所见,它只返回文本“Hello World”

其次,我用 Xcode 创建的动作。

但是当我运行工作流时......没有错误,但输入参数(即 NSArray)不包含任何内容!

您知道如何将 AppleScript 变量的内容传输到 Objective-C 动作吗?

感谢您的帮助。

【问题讨论】:

    标签: applescript xcode5


    【解决方案1】:

    我找到了!

    在“Automator Action 接受的输入类型”下的项目设置中,我将 com.apple.cocoa.path 替换为 com.apple.cocoa.string

    我得到了很好的价值。

    【讨论】:

      猜你喜欢
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      相关资源
      最近更新 更多