Applescript对文本框组进行indesign更改

Applescript对文本框组进行indesign更改,applescript,adobe,adobe-indesign,Applescript,Adobe,Adobe Indesign,我目前有一个AppleScript,可以对indesign文档中的文本框进行一些小的更改。脚本逐页进行,如果应用的对象样式被称为特定名称,并且包含特定字符,则将应用段落样式。以下是我的脚本示例: tell application "Adobe InDesign" repeat with x from 1 to count pages set ThisPage to page x tell ThisPage if exists (te

我目前有一个AppleScript,可以对indesign文档中的文本框进行一些小的更改。脚本逐页进行,如果应用的对象样式被称为特定名称,并且包含特定字符,则将应用段落样式。以下是我的脚本示例:

tell application "Adobe InDesign"
    repeat with x from 1 to count pages
        set ThisPage to page x
        tell ThisPage
            if exists (text frames whose (name of applied object style is "PriceBox" and contents contains "/$")) then
                set myFrames to (text frames whose (name of applied object style is "PriceBox" and contents contains "/$"))
                tell myFrames
                    repeat with r from 1 to count items
                        set applied paragraph style of paragraphs of item r of myFrames to "2forPrice"
                    end repeat
                end tell
            end if
        end tell
    end repeat
end tell
这样做的目的是转到文档的第一页,如果有一个名为“PriceBox”的文本框,并且该文本框中有“/$”字符,它将把段落样式更改为命名样式“2forPrice”

当每页上有1个“列表”时,这非常有效。我正试图在有多组列表的情况下实现这一点,并使脚本分别进入每一组框并运行脚本。有没有办法判断这是否可以通过小组而不是页面来完成

谢谢你的帮助

更新: 下面是它的屏幕截图,我跳过了几个步骤使它工作,但我更喜欢使用一组框。

图1:这就是所谓的“组”,我想把所有这些盒子放在一个组中

图2:这是所有组在一页上的布局

图3:如果是“2”的话,看看价格的变化,例如2/$6


我希望我的脚本能够一组一组地执行,而不是一页一页地执行if语句并更改段落样式。再次感谢你的帮助

我真的不知道如何在设计中工作-我有一份旧的副本,但如果您提供一个示例文档,我可以下载并测试它,那就太好了-但就AppleScript而言,您可能希望这样做:

tell application "Adobe InDesign"
    repeat with this_page in pages
        tell this_page
            set text_frames_list to (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
            repeat with a_text_frame in text_frames_list
                tell a_text_frame
                    set applied paragraph style of paragraphs of a_text_frame to "2forPrice"
                end tell
            end repeat
        end tell
    end repeat
end tell

我真的不知道如何在设计中工作-我有一份旧的副本,但如果您提供了一个示例文档,我可以下载并测试它,那就太好了-但就AppleScript而言,您可能希望这样做:

tell application "Adobe InDesign"
    repeat with this_page in pages
        tell this_page
            set text_frames_list to (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
            repeat with a_text_frame in text_frames_list
                tell a_text_frame
                    set applied paragraph style of paragraphs of a_text_frame to "2forPrice"
                end tell
            end repeat
        end tell
    end repeat
end tell

@Ted:根据应用程序的Apple事件对象模型的实现情况,您应该能够在一个命令中完成所有这些:

tell application "Adobe InDesign"
  tell front document
    tell pages
      tell (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
        set applied paragraph style of paragraphs to "2forPrice"
      end tell
    end tell
  end tell
end tell
(提示:Apple事件IPC是RPC+查询,而不是OOP。)

[ETA]正如下面的评论员所指出的,这在分组文本框架上不起作用,因此这里有一个递归变体:

to walkGroups(groupRef)
  tell application "Adobe InDesign CS6"
    tell groupRef
      tell (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
        if it exists then
          set applied paragraph style of paragraphs to "2forPrice"
        end if
      end tell
      repeat with subgroupRef in groups
        my walkGroups(subgroupRef)
      end repeat
    end tell
  end tell
end walkGroups


tell application "Adobe InDesign CS6"
  my walkGroups(front document)
end tell

@Ted:根据应用程序的Apple事件对象模型的实现情况,您应该能够在一个命令中完成所有这些:

tell application "Adobe InDesign"
  tell front document
    tell pages
      tell (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
        set applied paragraph style of paragraphs to "2forPrice"
      end tell
    end tell
  end tell
end tell
(提示:Apple事件IPC是RPC+查询,而不是OOP。)

[ETA]正如下面的评论员所指出的,这在分组文本框架上不起作用,因此这里有一个递归变体:

to walkGroups(groupRef)
  tell application "Adobe InDesign CS6"
    tell groupRef
      tell (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
        if it exists then
          set applied paragraph style of paragraphs to "2forPrice"
        end if
      end tell
      repeat with subgroupRef in groups
        my walkGroups(subgroupRef)
      end repeat
    end tell
  end tell
end walkGroups


tell application "Adobe InDesign CS6"
  my walkGroups(front document)
end tell

一行/故事法

如您所见,通过搜索页面、排列、粘贴板、组等来搜索文本框可能会很困难。脚本API没有“在布局中为我提供所有文本框,不管它们在哪里”的命令

这里的解决方法是使用故事对象。如果您要求InDesign为您提供版面中所有故事(或文本流)的列表,则无论它们在版面中的位置如何,您都可以获得它们

下面的示例从与文本框关联的所有故事开始,然后仅匹配文本框对象样式为“test”的故事。然后将段落样式应用于这些故事的段落

tell application "Adobe InDesign CC 2018"
        set applied paragraph style of paragraphs of (stories of document 1 whose class of (object reference of item 1 of text containers) is text frame and name of applied object style of item 1 of text containers = "test" and contents contains "/$") to "Body Text"
end tell
如果是嵌套的,则首选

tell application "Adobe InDesign CC 2018"
    tell document 1
        tell (stories whose class of (object reference of item 1 of text containers) is text frame and name of applied object style of item 1 of text containers = "test" and contents contains "/$")
            set applied paragraph style of paragraphs to "Body Text"
        end tell
    end tell
end tell

一行/故事法

如您所见,通过搜索页面、排列、粘贴板、组等来搜索文本框可能会很困难。脚本API没有“在布局中为我提供所有文本框,不管它们在哪里”的命令

这里的解决方法是使用故事对象。如果您要求InDesign为您提供版面中所有故事(或文本流)的列表,则无论它们在版面中的位置如何,您都可以获得它们

下面的示例从与文本框关联的所有故事开始,然后仅匹配文本框对象样式为“test”的故事。然后将段落样式应用于这些故事的段落

tell application "Adobe InDesign CC 2018"
        set applied paragraph style of paragraphs of (stories of document 1 whose class of (object reference of item 1 of text containers) is text frame and name of applied object style of item 1 of text containers = "test" and contents contains "/$") to "Body Text"
end tell
如果是嵌套的,则首选

tell application "Adobe InDesign CC 2018"
    tell document 1
        tell (stories whose class of (object reference of item 1 of text containers) is text frame and name of applied object style of item 1 of text containers = "test" and contents contains "/$")
            set applied paragraph style of paragraphs to "Body Text"
        end tell
    end tell
end tell
我认为你可以使用页面的“页面项目”。如果存在一个组,则该组将计为一个页面项。然后,您必须以编程方式检查每个组的文本框

例如,如果有3个文本框和一组2个文本框,则页面的文本框计数将为3,但页面项目计数将为4(三个未分组的文本框加上一组2个文本框。

我认为您可以使用“页面项目”如果有一个组,则它将计为一个页面项。然后,您必须以编程方式检查每个组的文本框


例如,如果有3个文本框和一组2个文本框,则页面的文本框计数将为3,但页面项目计数将为4(三个未分组的文本框加上一组两个文本框。

原则上是肯定的。在实践中,思想——至少在我的经验中——这种“密集”的编码往往会引起头痛。apple events系统是一种古老的技术。查询不如人们希望的那么健壮,调试任何错误都会迫使我们扩展您的隐式i我的意思是,如果它有效的话,你会有更多的能力;你的代码中有一个明确的“酷”因素。但是“酷”因素是有代价的。它不是“密集的”。它要么有效,要么无效。这取决于应用程序。如果一个query+命令无效,请重写脚本,使用循环通过多个命令发送更简单的查询,了解代码将更复杂、更容易出现错误且速度较慢。AppleScript有一个令人讨厌的习惯,那就是反复灌输用户根据假设工作,而不是重复某种程度上是不可避免的(由于无处不在的糟糕文档),沿着这条路走下去也是不可能的。没有什么比理论更像实践,natch。我的CC许可证只涵盖Illustrator,但我已经设法挖掘InDesign CS6,在一个模型文档上测试上述内容。似乎