Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 如何将applescript中隐藏在字符串中的变量转换为可读变量?_Variables_Applescript_Undefined - Fatal编程技术网

Variables 如何将applescript中隐藏在字符串中的变量转换为可读变量?

Variables 如何将applescript中隐藏在字符串中的变量转换为可读变量?,variables,applescript,undefined,Variables,Applescript,Undefined,我在applescript中制作了一个邮件宏,使用excel作为数据向不同的人发送邮件(例如,亲爱的,你的队友是和)。这个脚本很有效 为了使脚本更灵活,也可供其他人使用,我使用上面的伪代码将邮件消息放在文本文件中 themessage.txt Dear <firstname>, Your team mates are <teammate1> and <teammate2>. "Dear " & firstname & &q

我在applescript中制作了一个邮件宏,使用excel作为数据向不同的人发送邮件(例如,亲爱的,你的队友是和)。这个脚本很有效

为了使脚本更灵活,也可供其他人使用,我使用上面的伪代码将邮件消息放在文本文件中

themessage.txt

Dear <firstname>, Your team mates are <teammate1> and <teammate2>.
"Dear " & firstname & ","
并将其保存在变量中:

set themessage to “Dear “ & firstname & “, Your team mates are “ & teammate1 & “ and “ & teammate2 & “.”
不幸的是,这被解释为一个没有变量的长字符串

这就是我使用“运行脚本”的原因(请参阅:)。但是现在没有定义变量(、和)。它给出了脚本错误2753:未定义变量firstname

使用

这并不能解决问题

我已在以下代码中隔离了问题:

set firstname to "Alice" as text

--Read contents of themessage.txt. and save it to variable themessage
tell application "Finder"
    set current_path to container of (path to me) as text
end tell

set txtfile to (current_path & "themessage.txt") as alias
open for access txtfile
set themessage to (read txtfile)
close access txtfile

--Convert text string to command
run script "set thecontent to" & space & themessage
以及简化的themessage.txt

Dear <firstname>, Your team mates are <teammate1> and <teammate2>.
"Dear " & firstname & ","

要在带有“运行脚本”的行中识别变量firstname,我应该更改什么?

您可以将语句放入接受参数列表的
run
处理程序中,并使用
run script
命令的
with parameters
参数将参数传递给脚本。可以在列表中放置多个参数,这些参数与常规处理程序位置参数一样使用,例如:

set someVariable to "Alice"

set textFile to "path:to:message.txt" as alias -- the path to the text file
set theMessage to (read textFile) -- no need to use access for just reading

set theScript to "
on run {firstname} -- the variable names used in the script
   return " & theMessage & "
end run"

-- Run the script and get the result
set theResult to (run script theScript with parameters {someVariable}) -- the variables to pass to the script

有关详细信息,请参阅。

您可以将语句放入接受参数列表的
运行
处理程序中,并使用
运行脚本
命令的
带参数
将参数传递给脚本。可以在列表中放置多个参数,这些参数与常规处理程序位置参数一样使用,例如:

set someVariable to "Alice"

set textFile to "path:to:message.txt" as alias -- the path to the text file
set theMessage to (read textFile) -- no need to use access for just reading

set theScript to "
on run {firstname} -- the variable names used in the script
   return " & theMessage & "
end run"

-- Run the script and get the result
set theResult to (run script theScript with parameters {someVariable}) -- the variables to pass to the script
有关更多信息,请参阅