2013-05-11 39 views
0

我正在制作一个简单,紧凑的applescript计算器脚本。我知道问题是什么,但我不知道是否可以解决问题。当我运行脚本并输入数字时,它只是将方程式说回给我。我期望它能做到这一点,但是有没有办法让它做数学?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 
+1

通过编程来做数学? – Patashu 2013-05-12 00:00:15

回答

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 

随着运行脚本,你不会被锁定在繁殖中。任何数学序列都将如此评估。

+0

工程很棒。谢谢! – 2013-05-15 16:10:27

+0

除了那可能是危险的 – Cilan 2014-04-29 22:32:01

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 

希望这有助于...