2013-05-11 38 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 

希望這有助於...