0

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

2 回答 2

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

使用运行脚本,您也不会被锁定为乘法。任何数学序列都将被评估。

于 2013-05-14T20:42:19.877 回答
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

希望这可以帮助...

于 2013-05-12T00:46:58.663 回答