运行 Swift (Mac) 中的工作流程

Run a workflow in Swift (Mac)

大家好,

我有一个工作流文件,我想从 Swift Mac 应用中 运行。这是我当前的代码:

    @IBAction func onChangeMode(_ sender: Any) {
    guard let workflowPath = Bundle.main.path(forResource: "wf", ofType: "workflow") else {
            print("resource not found")
            return
        }

        let workflowURL = URL(fileURLWithPath: workflowPath)
        do {
            try AMWorkflow.run(at:workflowURL, withInput: nil)
        } catch {
            print("Error: \(error)")
        }
    }

但是,我不断收到此错误:

Error: Error Domain=com.apple.Automator Code=0 "Automator encountered an error running this workflow: “Sandboxed applications can not use Automator.framework to run workflows.”" UserInfo={NSUnderlyingError=0x600000cad8c0 {Error Domain=com.apple.Automator Code=0 "Sandboxed applications can not use Automator.framework to run workflows." UserInfo={NSLocalizedDescription=Sandboxed applications can not use Automator.framework to run workflows.}}, NSLocalizedDescription=Automator encountered an error running this workflow: “Sandboxed applications can not use Automator.framework to run workflows.”, NSLocalizedFailureReason=Sandboxed applications can not use Automator.framework to run workflows.}

我该如何解决这个问题?如果有人有解决方案,我将不胜感激 - 我是 Mac 开发的新手。

非常感谢大家,希望大家这段时间一切顺利。

如果您想要 运行 工作流程(这就是错误所说的!),您不能为您的应用使用沙箱,所以请转到此处:

然后按圆圈中的 "x" 按钮。请注意,没有沙盒的应用无法上传到 Mac App Store。