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

时间:2018-01-12 05:21:40

标签: applescript automator

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

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

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

1 个答案:

答案 0 :(得分:1)

由于您在Automator中使用Automator和AppleScript,并且您尚未发布任何实际代码,因此很难准确回答您正在寻找的内容。

可能有一个更简单的解决方案,但我提出的解决方案是创建一个脚本,将一个变量保存到一个新的脚本文件中(它将自动在桌面上创建,名称为“Stored_Variable.scpt”。第二个脚本加载存储在“Stored_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