使用AMWorkflow与沙盒应用程序(Using AMWorkflow with sandboxe

2019-10-17 04:34发布

我想从一个沙盒了AppKit的应用程序执行的Automator工作流。

最小示例+ GitHub库 :

   NSOpenPanel * panel = [NSOpenPanel openPanel];
   [panel setAllowsMultipleSelection:NO];
   [panel setCanChooseFiles:YES];
   [panel setCanChooseDirectories:NO];
   [panel setAllowedFileTypes:[NSArray arrayWithObject: @"com.apple.automator-workflow"]];
    NSInteger result = [panel runModal];

    if (result == NSFileHandlingPanelOKButton) {
      NSURL * workflow = [[panel URLs]objectAtIndex:0];
      NSLog(@"selected url %@", workflow);
      NSError * error = nil;
      [AMWorkflow runWorkflowAtURL:workflow withInput:[NSArray arrayWithObject:workflow] error:&error];
      if(error) {
          NSLog(@"Error while executing workflow %@", [error localizedDescription]);
      }        
    }

从我目前的AMWorkflow API的理解,我认为它使用马赫IPC在一个单独的Automator亚军过程中执行工作流。

这就是为什么我添加了以下权利,以我的应用程序:

   <key>com.apple.security.temporary-exception.mach-lookup.global-name</key>
   <array>
     <string>com.apple.AutomatorRunner</string>
     <string>com.apple.Automator</string>
   </array>

但很显然的Automator亚军尝试重新连接到失败,出现以下错误味精调用应用程序:

Automator Runner(2717) deny mach-lookup  /Users/pbrc/Library/Developer/Xcode/DerivedData/AMWorkflowCaller-arjgkslqihljquelyvybmpsnljrn/Build/Products/Debug/AMWorkf

0   libsystem_kernel.dylib          0x00007fff96ce9686 mach_msg_trap + 10
1   liblaunch.dylib                 0x00007fff8db637c4
2   liblaunch.dylib                 0x00007fff8db624d9 bootstrap_look_up3 + 69
3   liblaunch.dylib                 0x00007fff8db62609 bootstrap_look_up2 + 40
4   Foundation                      0x00007fff8f4acffe -[NSMachBootstrapServer portForName:options:] + 102
5   Foundation                      0x00007fff8f4b84cb +[NSConnection connectionWithRegisteredName:host:usingNameServer:] + 30
6   Automator Runner                0x0000000100001a51 -[AMRunnerDelegate processArguments] + 487

有任何想法吗?

Answer 1:

简单的答案是,AMWorkflow API并不在沙盒应用程序。 有哪些是最近引入的一种替代API,它与沙盒应用程序的工作原理:

NSUserAutomatorTask executeWithInput:completionHandler:

使用这个API,你可以执行位于应用程序的脚本文件夹的Automator脚本:

/用户/用户名/库/应用程序脚本/ BUNDLENAME.APPNAME

有一个显著警告:尽管该方法的“输入”的说法没有输入将通过之前10.8.3 12D75(这是/是一个bug)被传递到在Mac OS的版本的Automator工作流程:

NSUserAutomatorTask * task = [[NSUserAutomatorTask alloc] initWithURL:workflow error:&error];
if(error) {
    NSLog(@"Error while creating script task %@", [error localizedDescription]);
}

[task executeWithInput: @"this will never reach your workflow" completionHandler:^(id result, NSError *error){
    if(error)
        NSLog(@"Error while executing workflow %@", [error localizedDescription]);
}];


文章来源: Using AMWorkflow with sandboxed app