Applescript Compact计算器脚本问题

Applescript Compact计算器脚本问题,applescript,calculator,Applescript,Calculator,我正在用applescript制作一个简单、紧凑的计算器脚本。我知道问题是什么,但我不知道是否有可能解决它。当我运行脚本并输入数字时,它只会向我返回等式。我以为它会这么做,但有没有办法让它做数学呢 set theMultiply to text returned of (display dialog "What is the problem?" default answer "# * #" buttons {"Cancel", "Ok"} default button 2) set theAns

我正在用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

显示两个对话框,分别提示输入一个数字,然后将这两个数字相乘以形成一个结果,这样会容易得多。这是我为实现这一目标而编写的代码:

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

希望这有帮助…

您可以使用“运行脚本”评估数学:


使用run脚本,您也不会被锁定在乘法中。任何数学序列都将按此进行计算。

通过编程进行计算?但这可能是危险的
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