【问题标题】:Applescript to make indesign changes to group of text boxesApplescript 对文本框组进行 indesign 更改
【发布时间】:2020-02-02 21:24:05
【问题描述】:

我目前有一个 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:如果是“2for”的话,看看价格的变化,例如2/$6

我希望我的脚本按组而不是逐页执行 if 语句并更改段落样式。再次感谢您的帮助!

【问题讨论】:

    标签: applescript adobe adobe-indesign


    【解决方案1】:

    @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
    

    【讨论】:

    • 原则上,当然可以。在实践中,认为——至少在我的经验中——这种“密集”的编码往往会让人头疼。苹果事件系统是技术。查询并不像人们希望的那样健壮,调试任何错误都会迫使我们将您的隐式迭代扩展为我编写的显式迭代。我的意思是,如果它有效,会给你更多的力量;您的代码有一个明确的“酷”因素。但“酷”因素是有代价的。
    • 它不是“密集”的。它要么有效,要么无效。这取决于应用程序。如果单个查询 + 命令不起作用,则重写您的脚本以使用循环在多个命令上发送更简单的查询,了解代码将更复杂、更容易出错且速度较慢。 AppleScript 有一个讨厌的习惯,即灌输用户进行假设,虽然在某种程度上是不可避免的(由于无处不在的文档不足),但在这条路上cargo cult programming 也是谎言。
    • 没有什么比实践更能胜过理论了,natch。我的 CC 许可证仅涵盖 Illustrator,但我设法挖掘出 InDesign CS6 以在模型文档上测试上述内容。似乎工作正常,一旦我添加了tell document… 块(我们都忘记了:)。 AI 和 ID AEOM 有很多怪癖,但总的来说,它们仍然是“AppleScript”生态系统中最彻底和最强大的实现。令人惊叹的技术,当它起作用时。
    • 您好,我已将脚本在价格框中的确切操作附在屏幕截图上。再次感谢您的帮助!
    • @user:嗯,这很烦人。 (显然我的 ID-fu 已经生锈了。Illustrator 没有这个限制:every page item of document 指的是 所有 对象,无论层或分组如何。)您使用 stories of document 的建议可能效果最好,请注意需要按文本框架格式进行过滤(如果故事流经多个文本框架,这可能无法按预期工作)。如果没有,我已经修改了我的原始答案以遍历嵌套组。
    【解决方案2】:

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

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

    【讨论】:

    • 这很有帮助,但不是完整的答案。
    【解决方案3】:

    单线/故事方法

    如您所见,通过搜索页面、跨页、粘贴板、组等来搜索文本框架可能很困难。脚本 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
    

    【讨论】:

      【解决方案4】:

      我真的不知道如何使用 InDesign - 我有它的旧副本,但如果您提供一个示例文档,我可以下载和测试,那就太好了 - 但就 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
      

      【讨论】:

      • 不处理分组文本框
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      相关资源
      最近更新 更多