代码之家  ›  专栏  ›  技术社区  ›  needshelp

从单独的工作流更改工作流中的变量

  •  -1
  • needshelp  · 技术社区  · 7 年前

    我有两个工作流,我需要将一个工作流中生成的值传递给另一个工作流。

    在我的第一个工作流中,我有一个AppleScript,它返回一个我想输入到第二个工作流中的数字,我从第一个工作流调用该数字,如下所示: enter image description here

    我的第二个工作流(在iStudiez中创建类)有一个变量“Class Number”,当我从第一个工作流调用它时,我想更改它,返回值为上图中的AppleScript。

    1 回复  |  直到 7 年前
        1
  •  1
  •   wch1zpink    7 年前

    由于您正在Automator中使用Automator和AppleScript,并且您还没有发布任何实际代码,因此很难给出您所要查找的内容的确切答案。

    可能有一个更简单的解决方案,但我想到的解决方案是创建一个脚本,将变量保存到新的脚本文件中(该脚本将在桌面上自动创建,名称为Stored\u variable.scpt。第二个脚本加载存储在Stored\u variable.scpt文件中的变量的值)。

    只需将第一个脚本中的代码直接粘贴到包含要复制的变量的代码中。确保将代码粘贴在设置要复制的变量值的代码之后。

    --  Comment Out This Next Line Before
    --    Placing This Code Into Your Script
    --    Which Contains The Variable You Want Copied
    
    set originalVariable to (path to desktop) -- Testing Purposes Only
    
    -- Replace "originalVariable" with the
    --   Name Of Your Actual Variable You Want To Pass
    --   To The Next Script
    
    set saveThisVariable to originalVariable
    storeTheVariable()
    
    -- The Following Code Belongs At The Very Bottom Of Your Script
    on storeTheVariable()
        set storedVariabeFileLocation to (path to desktop as text) & "Stored_Variable.scpt"
        ----------------------
        script theVariable
            set saveThisVariable to saveThisVariable
        end script
        ----------------------
        store script theVariable in ¬
            file storedVariabeFileLocation with replacing
    end storeTheVariable
    

    将这是第二个代码放在AppleScript的代码中,您将在其中尝试从第一个AppleScript代码中检索存储的变量

    -- Gets The Variable Which Was Previously Stored
    --   From The Other Applescript And Stores It In A
    --   New Variable... getVariableNow
    
    set getVariableNow to run loadTheVariable
    
    -- -----------------------------------
    
    -- Place Whatever Commands Here, That You Will Be Using
    --   The New Variable... getVariableNow with
    
    -- -----------------------------------
    
    -- The Following Code Belongs At The Very Bottom Of Your Script
    script loadTheVariable
        property storedVariabeFileLocation : (path to desktop as text) & "Stored_Variable.scpt"
        property theRetrievedVariable : missing value
        on getStoredVariable()
            set theScript to load script file storedVariabeFileLocation
            set theRetrievedVariable to saveThisVariable of (theVariable of theScript)
        end getStoredVariable
        set theRetrievedVariable to loadTheVariable's getStoredVariable()
    end script