gpt4 book ai didi

macos - NSUserAutomatorTask 变量数组/列表值无法被 Automator 操作解析

转载 作者:行者123 更新时间:2023-12-03 18:07:35 24 4
gpt4 key购买 nike

我正在使用 NSUserAutomatorTask 从 macOS 应用启动 Automator 工作流程。

我通过 variables 属性传入变量: https://developer.apple.com/documentation/foundation/nsuserautomatortask/1418099-variables

在 Automator 工作流程中,我将使用 获取变量值 操作来获取在 NSUserAutomatorTask 上设置的变量,并将这些变量传递给后续 Automator 操作:

Get Value of Variable

<小时/>

代码如下所示:(简化;我还在工作流程中check that the variables exist)

let workflow = try! NSUserAutomatorTask(url: url)
workflow.variables = [
"singleFilePath": "/image1.png",
"multipleFilePaths": ["/image1.png", "/image2.png"],
]
workflow.execute(withInput: nil)

我可以通过请求确认操作打印出警报中的变量值:

variable string values.

String 变量的值是一个简单的字符串:/image1.png

[String] 数组变量的值包含在括号中,并且每一项都用引号引起来:

(
"/image1.png",
"/image2.png"
)
<小时/>

我现在运行如图所示的 Automator 工作流程,该工作流程首先获取变量的值,然后尝试打开这些 Finder 项目。

singleFilePath var 有效。它被传递到“打开查找器项目”操作,并且该文件由默认应用程序打开。

以相同方式传递multipleFilePaths 不起作用。没有文件被打开。 Automator 显示错误:

The action "Open Finder Items" was not supplied with the required data.

<小时/>

该操作是“打开 Finder 项目s”,因此必须有某种方法将多个文件路径传递给此操作。

我的问题和解决方案按优先顺序排列是:

  1. 为什么默认变量数组/列表格式在传递给后续操作时不起作用?有没有办法以兼容的格式传递或解析数组变量?

  2. 我们可以使用单个 Run AppleScript 操作将数组变量重新格式化为可以传递给后续 Automator 操作的格式吗? (我想继续链接 Automator 操作而不是运行纯 AppleScript)。

最佳答案

如果在正常的非变量工作流程中使用,

打开 Finder 项目操作可以打开项目数组。而且格式似乎完全相同。

作为测试此功能的控件,而不是变量,我使用 获取指定的查找器项目 操作。

然后,我使用查看结果操作来检查发送到Open Finder Items的内容。

结果看起来与我解析变量时的结果完全相同:

(
"/image1.png",
"/image2.png"
)

Get Specified Finder Items

此工作流程确实正确运行最终操作并打开文件。

因此,Open Finder Items 应该可以使用我在变量中设置的数据。我不确定为什么可变数据无法打开,但手动选取的文件可以。

<小时/>

我针对此问题提交了 DTS 票证并收到以下回复:

I’m sorry to say the engineers working on this have confirmed that yes, it’s a bug, and no, there isn’t a workaround for sandboxed apps. They’ve also noted this isn’t a regression in behavior from previous releases.

关于macos - NSUserAutomatorTask 变量数组/列表值无法被 Automator 操作解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61268835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com