AppleScript的Automator库中的`add`命令的正确语法是什么?

时间:2014-03-09 11:21:42

标签: applescript pdf-generation workflow automator

目标

我想使用AppleScript打开Automator并将特定操作添加到新的工作流程,而不管本地化设置(语言)如何。换句话说,我想使用AppleScript打开一个新的Automator工作流,并使用每个操作的包标识符(以避免语言问题)或以其他方式避免语言问题,以特定顺序(在索引处)添加特定操作。

问题

问题在于我无法让Automator向工作流程添加任何内容。

  • add命令的语法是什么?
  • 我可以使用捆绑ID来添加操作吗?

到目前为止,这就是我所拥有的:

tell application "Automator"
    make new workflow with properties {name:"Merge PDF Files"} -- Skips Opening Dialog
    add "Get Specified Finder Items" to workflow 1 at index 1 --("com.apple.Automator.SpecifiedFiles")
    add "PDF-Seiten kombinieren" to workflow 1 at index 2 --("com.apple.action.joinpdf")
end tell

合并PDF文件Droplet的完整代码

在bwaldie发布他的回答之后,我想分享我的有用液滴。你可以将它放在任何运行OS X的Mac上(对于不熟悉Automator的人特别有用)。要使用它,只需将代码粘贴到AppleScript编辑器中并将其另存为应用程序。

请参阅droplet的代码:

on open the_Droppings
    -- CONVERT INPUT LIST OF ALIASES TO POSIX PATHS
    repeat with itemStep from 1 to count of the_Droppings
        set item itemStep of the_Droppings to POSIX path of item itemStep of the_Droppings
    end repeat
    tell application "Automator"
        activate
        set theWorkflowName to "Merge PDF Files"
        set msg to "no"
        tell application "Finder" to if exists POSIX path of ((path to temporary items as string) & theWorkflowName & ".workflow" as string) as POSIX file then set msg to "yes"
        if msg is "no" then
            set myWorkflow to make new workflow with properties {name:theWorkflowName, path:POSIX path of ((path to temporary items as string) & theWorkflowName & ".workflow" as string)}
            add (first Automator action where its id = "com.apple.Automator.SpecifiedFiles") to myWorkflow at index 1
            add (first Automator action where its id = "com.apple.action.joinpdf") to myWorkflow at index 2 --("com.apple.Automator.SpecifiedFiles")
        else
            set myWorkflow to open POSIX path of ((path to temporary items as string) & theWorkflowName & ".workflow" as string)
        end if

        set actionsList to name of Automator action of myWorkflow
        set firstAction to item 1 of actionsList
        tell myWorkflow
            set value of setting of Automator action firstAction to the_Droppings -- MUST BE LIST OF POSIX PATHS
        end tell
    end tell
end open

2 个答案:

答案 0 :(得分:1)

尝试一下......

set theWorkflowName to "Merge PDF Files"
tell application "Automator"
    set myWorkflow to make new workflow with properties {name:theWorkflowName, path:POSIX path of ((path to desktop folder as string) & theWorkflowName & ".workflow" as string)}
    save myWorkflow
    add (first Automator action where its id = "com.apple.Automator.SpecifiedFiles") to myWorkflow
end tell

我认为关键是创建工作流程,然后保存,然后添加操作。

希望这有帮助!

-Ben

答案 1 :(得分:0)

如果您想使用Automator,则无需编写脚本。这对我有用:

  1. 启动Automator;
  2. 创建新服务或例如创建新的工作流程;
  3. 如果您创建了服务,请选择“服务接收PDF文件” Finder.app“位于窗口顶部;如果选择Workflow,请选择 档案& FOlders在左侧的Actions列表中并拖动Get 选择的Finder项目在右侧,并确保选择了追加页面;
  4. 在“操作”列表中选择PDF并拖动“将PDF页面合并到右侧”
  5. 在“操作”列表中选择“文件和文件夹”,然后将“复制查找器项目”向右拖动并确保选中“桌面”
  6. 向右拖动“Make Finder Item Names Sequential”,选择Make Sequential“和”将数字添加到现有项目名称“。
  7. 您可能需要稍微调整并尝试使用Automator,以确保它完全符合您的要求。