【问题标题】:Automator Quick Action - Run AppleScript on each item in folderAutomator 快速操作 - 对文件夹中的每个项目运行 AppleScript
【发布时间】:2021-12-26 07:05:09
【问题描述】:

我正在尝试在 Automator 中构建一个可以在任何文件夹上运行的快速操作,它将在该文件夹内的每个 .pdf 文件上逐个运行以下 AppleScript - 等待第一个完成,然后再开始下一个文件。

目前我只有想要运行的 AppleScript 代码,但我不知道如何将其附加到快速操作并使其在内部的每个 pdf 项目上运行代码。

注意:文件夹中PDF文件的数量每次可以不同。

on run {input, parameters}

    set theFile to input's item 1

    set theSeconds to time of (current date)

    tell application "Finder"
        set theDuplicate to duplicate file "Macintosh HD:Users:username:Documents:IddTest:template.indd"
    end tell

    tell application "Adobe InDesign 2020" to open file (theDuplicate as string)

    tell application "Adobe InDesign 2020"
        if document 1 exists then
            repeat 34 times
                tell document 1
                    relink link "placeholder.pdf" to theFile
                    try
                        update link "placeholder.pdf"
                    end try
                end tell
            end repeat
        end if
    
        close document 1 saving yes
    end tell

    tell application "Finder"
        set name of theDuplicate to "" & theSeconds & ".indd"
    end tell

end run

【问题讨论】:

    标签: applescript automator


    【解决方案1】:

    请注意,我没有 Adobe InDesign 2020,因此我对您的 AppleScript 代码 的返工尚未经过测试,但我相信它应该工作。

    • Automator 中创建一个新的工作流 作为 Quick Action,其设置如下图所示。

    • 添加一个获取文件夹内容 动作

    • 添加一个 Filter Finder Items action,其设置如下图所示。

    • 添加 Run AppleScript action 将默认 code 替换为 AppleScript code 下面。

    示例 AppleScript 代码

    on run {input, parameters}
    
        repeat with thisFile in input
    
            set theSeconds to time of (current date)
    
            tell application "Finder"
                set theDuplicate to duplicate file "Macintosh HD:Users:username:Documents:IddTest:template.indd"
            end tell
    
            tell application "Adobe InDesign 2020"
                open file (theDuplicate as string)
                delay 2
                if document 1 exists then
                    repeat 34 times
                        tell document 1
                            relink link "placeholder.pdf" to thisFile
                            try
                                update link "placeholder.pdf"
                            end try
                        end tell
                    end repeat
                end if
                close document 1 saving yes
            end tell
    
            tell application "Finder"
                set name of theDuplicate to "" & theSeconds & ".indd"
            end tell
        
        end repeat
    
    end run
    


    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2016-09-08
      • 2019-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 2013-08-15
      相关资源
      最近更新 更多