1

让我先说一下,我知道我可以使用 Filemaker 计算的 Apple Script 轻松执行以下操作。我真的很想知道如何在 Apple Script 中实现这一点。我正在尝试将变量设置到一个名为 Keyboard Maestro 的宏程序中,我将其称为 KM。

我的脚本首先遍历 Filemaker 中找到的记录,并从每个找到的记录中复制数据。我不知道如何从 Apple Script 中的循环中设置 KM 变量,因为据我所知,您无法动态设置 Apple Script 变量的名称。

我可以通过创建一个列表来创建变量的名称(我想使用):

set variableListFunderName to {}
set i to 1
repeat until i = winCount + 1

    copy "Business_ExistingAdvance" & i & "FunderName" to the end of variableListFunderName
    set i to i + 1
end repeat



set variableListFundingCurrentBalance to {}
set i to 1
repeat until i = winCount + 1

    copy "Business_ExistingAdvance" & i & "FundingCurrentBalance" to the end   of variableListFundingCurrentBalance
    set i to i + 1
end repeat




set variableListFundingAmount to {}
set i to 1
repeat until i = winCount + 1

    copy "Business_ExistingAdvance" & i & "FundingAmount" to the end of variableListFundingAmount
    set i to i + 1
end repeat

--

但是当我将字段的内容设置为我创建的列表项时,变量不会显示在 KM 中:

--

set i to 1


repeat until i = winCount + 1
    tell record i

        set item i of variableListFunderName to cell "Funders_ExistingAdvances::FunderCompanyName"
        set item i of variableListFundingCurrentBalance to cell "FundingCurrentBalance"
        set item i of variableListFundingAmount to cell "FundingAmount"
    end tell

    ignoring application responses
        tell application "Keyboard Maestro Engine"

            setvariable item i of variableListFunderName & "_AS" to item i of variableListFunderName
            setvariable item i of variableListFundingCurrentBalance & "_AS" to item i of variableListFundingCurrentBalance
            setvariable item i of variableListFundingAmount & "_AS" to (item i of variableListFundingAmount)
        end tell
    end ignoring
    set i to i + 1
end repeat

如何设置这些 KM 变量?

4

1 回答 1

1

您不能使用 applescript 创建动态变量。

您当前所做的是生成字符串并将它们添加到列表中。然后你用其他值替换这些字符串,这样字符串就会丢失。

但是你可以在 applescript Objective-c 的帮助下实现这一点:

use framework foundation

set variableListFunderName to {}
set i to 1
repeat until i = winCount + 1

    copy "Business_ExistingAdvance" & i & "FunderName" to the end of variableListFunderName
    set i to i + 1
end repeat

set funderNameDict to current application's NSMutableDictionary's alloc()'s init()

repeat with var in variableListFunderName
 funderNameDict's setObject:"yourValue" forKey:var
end repeat

然后你可以访问动态值

set myValue to funderNameDict's objectForKey:"yourDynamicVarName"

循环使用字典

repeat with theKey in funderNameDict's allKeys()
set myValue to funderNameDict's objectForKey:theKey
end repeat 
于 2017-04-28T05:28:14.337 回答