如何在 InDesign 中使用 applescript 按脚本标签 select 文本框?

How can I select a text frame by script label using applescript in InDesign?

我正在尝试使用 AppleScript select 通过使用预先存在的唯一标签在 InDesign 文档中预先存在的文本框架,然后修改这些文本框架的填充颜色和大小。 (这是一个更大的工作流的一部分,它根据列表中的值调整大约 100 个这样的框架的这些属性。文本框架的标签也在列表中,并且标签和值的位置在他们各自的列表,着眼于将其放入循环中。)

在我下面的示例代码中,“Fred”是我的文本框的标签,“Secondary 1”是我试图设置为文本框的填充颜色的色样的名称,我'尝试在不更改任何其他几何边界的情况下将文本框的宽度指定为 107 mm。

set labelList to {"Fred","Alice","Bob"}
set valueList to {107,42,42}

tell application "Adobe InDesign 2020"
    set myDocument to active document -- presumes you've already done a data merge.
    tell myDocument
        set testFrame to every text frame whose label is item 1 of labelList
        copy geometric bounds of testFrame to {x0, y0, x1, y1}
        set geometric bounds of testFrame to {x0, y0, (x0 + item 1 of valueList), y1}
        set fill color of testFrame to {"Secondary 1"}
    end tell
    
end tell

失败并出现以下错误:

"Can’t get geometric bounds of {text frame id 6546 of spread id 5872 of document id 2 of application "Adobe InDesign 2020"}." number -1728 from «class gbnd» of {«class txtf» id 6546 of «class sprd» id 5872 of document id 2}

错误为我提供了一个文本框 ID 号这一事实让我认为我成功地select使用标签“Fred”创建了文本框,但我没有充分指定以下几行中的内容。因此脚本无法正确读取或设置该文本框的属性。

我遇到过很多用于创建文本框并设置其属性的脚本示例,网站上也有一个类似的问题用于设置文本框内文本的属性 - 但这种情况下的答案是文本的属性由不同的对象持有,所以没有太大帮助。

如有任何建议,我们将不胜感激!

可能是因为还是这个错字?

set valueList to (107,42,42}

可能应该有 { 而不是 ((反之亦然,我不知道 AppleScript)

声明

set testFrame to every text frame whose label is item 1 of labelList

returns一个列表。如果您将 testFramesToProcess 命名为然后

,那就不会那么混乱了
set testFrame to item 1 of testFramesToProcess