我正在将一些代码从AMWorkflow迁移到NSUserAutomatorTask,这样我最终可以沙箱化我的应用程序.我希望能够在AMWorkflow中设置工作流中现有变量的值,其中:
AMWorkflow *task = [[AMWorkflow alloc] initWithContentsOfURL:scriptURL error:nil];
[task setValue:@"myValue" forVariableWithName:@"myVar"];
Run Code Online (Sandbox Code Playgroud)
但是,我似乎无法使用NSUserAutomatorTask获得类似的功能.我能找到的唯一文档(类引用)表示将变量作为NSDictionary提供.
所以我正在尝试这样的事情:
NSUserAutomatorTask * task = [[NSUserAutomatorTask alloc] initWithURL:workflow error:nil];
task.variables = [NSDictionary dictionaryWithObject:@"myValue" forKey:@"myVar"];
[task executeWithInput:nil completionHandler:^(id result, NSError *error){
if(error)
NSLog(@"Error while executing workflow %@", [error localizedDescription]);
}];
Run Code Online (Sandbox Code Playgroud)
我在另一个答案(使用带有沙盒应用程序的AMWorkflow)中读到,忽略了NSUserAutomatorTask的"executeWithInput:"提供的值.变量是否也可能?