【问题标题】:How can I launch an Automator application using AppleScript?如何使用 AppleScript 启动 Automator 应用程序?
【发布时间】:2014-07-21 17:19:19
【问题描述】:

我正在尝试使用 Remote Buddy 来控制 Photo Booth,但我需要一种在静止模式和视频模式之间切换的方法,我的解决方案是使用 Automator 应用程序选择两个单选按钮中的一个或另一个按下遥控按钮。

我已经创建了 .app,当我从桌面双击它时它运行良好,但我需要一种从 Remote Buddy 中启动 .app 的方法,AppleScript 似乎是我唯一的选择。

tl;博士

我需要能够使用 AppleScript 启动 Automator .app 文件,但无法找出正确的语法。

【问题讨论】:

    标签: applescript


    【解决方案1】:

    如果我制作了一个名为 Untitled 的 Automator 应用程序,我将使用此命令启动它 tell application "Untitled" to activate

    使用以下方法之一创建应用程序后,可以通过其名称在任何其他脚本中访问该应用程序。它是全局定义的,就像你 Mac 上的任何其他应用程序一样。只需使用tell application "app Name"

    创建应用程序的两种方式:

    【讨论】:

    • 应用名称是全球性的吗?我需要先导航到某个目录,还是可以在任何地方工作?
    【解决方案2】:
    activate app ((system attribute "HOME") & "/Desktop/test.app/")
    

    您也可以使用automator shell 命令。

    automator test.workflow
    automator test.app
    automator test.workflow -v # verbose
    automator -i lol test.workflow
    echo lol | automator -i - test.workflow
    automator -i $'lol\nlol2' test.workflow # \n separates input strings
    automator -d somevar=somevalue test.workflow
    

    【讨论】:

      【解决方案3】:

      您首先将您的自动化应用程序命名为“photobooth.app”,然后您将在 applescript 中输入一个类型

      tell application "photobooth.app"
      activate
      end tell
      

      【讨论】:

        【解决方案4】:

        我直接使用 Automator 脚本编写。这不会访问应用程序,而是访问工作流。这是有利的,因为您可以编辑一些单独的工作流程项目的设置/内容。

        我想我的回答会更适合这个问题:

        如何使用 AppleScript 启动 Automator 工作流程

        我发现首先保存 Automator 操作可以避免出现问题。例如

        set theWorkflowName to "Merge PDF Files"
        set myWorkflow to make new workflow with properties {name:theWorkflowName, path:POSIX path of ((path to temporary items as string) & theWorkflowName & ".workflow" as string)}
        set myWorkflow to open POSIX path of ((path to temporary items as string) & theWorkflowName & ".workflow" as string)
        

        合并 PDF 文件 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 myWorkflow to open POSIX file "/Users/USERNAME/Dropbox/Scripts/Automator/Workflows/merge PDF files.workflow"
            set actionsList to name of Automator action of myWorkflow
            set firstAction to item 1 of actionsList
            tell myWorkflow
                (*
                get index of Automator action firstAction
                get input types of Automator action firstAction
                get path of Automator action firstAction
                get path of Automator action firstAction
                get value of setting of Automator action firstAction
                *)
                set value of setting of Automator action firstAction to the_Droppings -- MUST BE LIST OF POSIX PATHS
            end tell
        end tell
        end open
        

        【讨论】:

          猜你喜欢
          • 2021-10-08
          • 1970-01-01
          • 2011-12-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-01-07
          • 1970-01-01
          相关资源
          最近更新 更多