我正在使用applescript制作一个简单,紧凑的计算器脚本。我知道问题是什么,但我不知道是否有可能解决它。当我运行脚本并输入数字时,它只是将方程式说回给我。我希望它能做到这一点,但有没有办法让它做数学?
set theMultiply to text returned of (display dialog "What is the problem?" default answer "# * #" buttons {"Cancel", "Ok"} default button 2)
set theAnswer to theMultiply
display dialog theAnswer buttons {"Cancel", "Ok"} default button 2
答案 0 :(得分:1)
您可以使用“运行脚本”评估数学:
set theMultiply to text returned of (display dialog "What is the problem?" default answer "# * #" buttons {"Cancel", "Ok"} default button 2)
set theAnswer to run script theMultiply
display dialog theAnswer
使用运行脚本,您也不会被锁定。任何数学序列都将被评估。
答案 1 :(得分:0)
显示两个对话框会更容易,每个对话框提示一个数字,然后将这两个数字相乘以形成结果。这是我提出的代码:
set term1 to getNewTerm("Enter the first number to be multiplied")
set term2 to getNewTerm("Enter the second number to be multiplied")
set answer to term1 * term2
display dialog (term1 as string) & " * " & (term2 as string) & " is " & (answer as string)
on getNewTerm(message)
set numError to missing value
repeat until numError is false
try
set newTerm to text returned of (display dialog message default answer "") as number
set numError to false
on error
display dialog "Please enter a number"
set numError to true
end try
end repeat
return newTerm
end getNewTerm
希望这会有所帮助......