动态命名apple脚本变量

从来好事天生俭,自古瓜儿苦后甜。这篇文章主要讲述动态命名apple脚本变量相关的知识,希望能为你提供帮助。
让我先说一下,我知道我可以使用Filemaker的计算Apple脚本轻松完成以下操作。我真的很想知道如何在Apple Script中完成这个任务。我正在尝试将变量设置为名为Keyboard Maestro的宏程序,我将其称为KM。
我的脚本首先遍历Filemaker中找到的记录,并从每个找到的记录中复制数据。我无法弄清楚如何从Apple Script中的循环设置KM变量,因为据我所知,您无法动态设置Apple Script变量的名称。
我可以通过创建一个列表来创建变量的名称(我想使用):

set variableListFunderName to {} set i to 1 repeat until i = winCount + 1copy "Business_ExistingAdvance" & i & "FunderName" to the end of variableListFunderName set i to i + 1 end repeatset variableListFundingCurrentBalance to {} set i to 1 repeat until i = winCount + 1copy "Business_ExistingAdvance" & i & "FundingCurrentBalance" to the endof variableListFundingCurrentBalance set i to i + 1 end repeatset variableListFundingAmount to {} set i to 1 repeat until i = winCount + 1copy "Business_ExistingAdvance" & i & "FundingAmount" to the end of variableListFundingAmount set i to i + 1 end repeat

--但是当我将字段的内容设置为我创建的列表项时,变量不会显示在KM中:
--
set i to 1repeat until i = winCount + 1 tell record iset 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 tellignoring 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变量?
答案您无法使用applescript创建动态变量。
您目前所做的是生成字符串并将其添加到列表中。然后用其他值替换这些字符串,这样字符串就会丢失。
但你可以在applescript objective-c的帮助下实现这一点:
use framework foundationset variableListFunderName to {} set i to 1 repeat until i = winCount + 1copy "Business_ExistingAdvance" & i & "FunderName" to the end of variableListFunderName set i to i + 1 end repeatset 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"

【动态命名apple脚本变量】循环使用字典
repeat with theKey in funderNameDict's allKeys() set myValue to funderNameDict's objectForKey:theKey end repeat


    推荐阅读